Question: Implement the stack using a linked list. Use the following class definition for the stack and use... Implement the stack using a linked list. Use

Implement the stack using a linked list. Use the following class definition for the stack and use...


Implement the stack using a linked list. Use the following class definition for the stack and use the given main function to test your implementation. #include typedef int StackElement; struct node { StackElement data; node * next; }; class Stack { public: Stack(); // create an empty stack bool empty(); //return true if stack is empty, otherwise return false void push(StackElement x); //add a new value to the top of the stack bool Top(StackElement & x); //retrieves the data that is at the top of the stack void pop(); //removes the value at the top of the stack void display(); //displays the data stored in the stack private: node * mytop; //pointer to the top of the stack }; int main() { Stack S; // insert values 10, 20, 30, 40 and 50 onto the stack for(int x = 1; x=5;> int n = x*10; S.push(n); } //Display the content of the stack to the screen S.display(); cout //Remove and display each value on the stack while (!S.empty()) { int x; S.Top(x); cout coutpopping> S.pop(); S.display(); } if (S.empty()) cout }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!