Question
this is the assingment : Create a class/struct for a node. Create a class/struct for a list. Members: Top - a node that tracks the
this is the assingment :
Create a class/struct for a node. Create a class/struct for a list. Members: Top - a node that tracks the top of the stack Count - indicates how many items are on the stack. Methods: Push - Accepts a number and adds to the top of the stack. Pop - Returns a number from the top of the stack. - If the stack is empty, emit an error indicating the stack is empty. IsEmpty - Returns a boolean indicating if the stack is empty.
this is the code I have so far :
#include#include using namespace std; struct node { int info; struct node *link; } *top; class stackLineup { public: node *push(node *, int); node *pop(node *); void pass(node *); stackLineup() { top = 0; } }; int main() { int choice, item; stackLineup sl; while (true) { cout<<" ~~~~~~~~~~~~~~~~~"< ~~~~~~~~~~~~~~~~~~~~~~"< ~~~~~~~~~~~~~~~~~"< ~~~~~~~~~~~~~~~~~"< ~~~~~~~~~~~~~~~~~"< ~~~~~~~~~~~~~~~~~"< >choice; switch(choice) { case 1: cout<<"ENTER THE NUMBER TO PUSH INTO THE STACK!!!: "; cin>>item; top = sl.push(top, item); break; case 2: top = sl.pop(top); break; case 3: sl.pass(top); break; case 4: exit (4); break; default: cout<<"beeeeeeeeeeeeeeeeep, nope"< return 4; } node *stackLineup::push(node *top, int item) { node *tmp; tmp = new (struct node); tmp->info = item; tmp->link = top; top = tmp; return top; } node *stackLineup::pop(node *top) { node *tmp; if (top == 0) cout<<"ERROR!!!!! ERORR!!!!!! STACK IS EMPTY********************"< else { tmp = top; cout<<"num pooped: "< info< link; free(tmp); } return top; } void stackLineup::pass(node *top) { node *ptr; ptr = top; if (top == 0) cout<<"ERROR!!!!! ERORR!!!!!! STACK IS EMPTY********************"< else { cout<<"heres your stack: "< while (ptr != 0) { cout< info< link; } } }
please add a count member to the code that
Count - indicates how many items are on the stack.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started