Create a program that uses a derived class based on the list class you’ve create
ID: 3848539 • Letter: C
Question
Create a program that uses a derived class based on the list class you’ve created in the first
program. This program will use a stack data type.
class node {
void *info;
node *next;
public:
node (void *v) {info = v; next = 0; }
void put_next (node *n) {next = n;}
node *get_next ( ) {return next;}
void *get_info ( ) {return info;}
};
class list {
node *head;
int node_num;
public:
list ( ) { node_num = 0; head = 0;}
void remove (int);
void insert (void *, int);
void append (void * v) {insert (v, node_num + 1); }
void *find (int);
void display ( );
};
Write functions to push and pop the stack. Write a driver main program which gives 5 values (5
nodes created) that will push, pop and display data stored.
Explanation / Answer
Hi,
I have provided the code below. Note that it won't work unless you complete the definition of list class. Since it wasn't mentioned in the question, I haven't implemented it. I have just extended the list class assuming it completed and used its methods and provided the pop and push methods. The main methods gives an example demonstrating the stack class.
//Code starts here
//Code ends here
Hope it helps!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.