Write a C++ program to simulate a stack using an array. You should create an index (the stack pointer) to point into the stack. Initialize it to 0. The stack should grow to location [1], [2], [3], etc. Write a "push (int)" function to push an int onto the top of the stack. Also, write an "int pop" instruction to pop the data that is stored on the top of the stack. The pop instruction must return the popped data. The push and pop instructions should increment and decrement the stack pointer appropriately. Your source should contain calls to your functions demonstrating that it works. Note, that you should do several pushes and several pops to show that data is correctly stored on the stack. You can do this by showing sample runs. Cut and paste the results of the runs
Write a C++ program to simulate a stack using an array. You should create an index (the stack pointer) to point into the stack. Initialize it to 0. The stack should grow to location [1], [2], [3], etc. Write a "push (int)" function to push an int onto the top of the stack. Also, write an "int pop" instruction to pop the data that is stored on the top of the stack. The pop instruction must return the popped data. The push and pop instructions should increment and decrement the stack pointer appropriately.
Your source should contain calls to your functions demonstrating that it works. Note, that you should do several pushes and several pops to show that data is correctly stored on the stack. You can do this by showing sample runs. Cut and paste the results of the runs
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images