Answer to Question #29351 in C++ for curtis tandoh
2013-04-27T15:18:01-04:00
1. Using an array of size 10, implement the PUSH and POP operations of the stack. NB: Let your TOP and BOTTOM be -1 when that stacks is EMPTY.
2. Convert your algorithm above into a c++ code
1
2013-04-30T09:08:43-0400
#include <iostream> using namespace std; typedef int my_type; #define SZ 10 my_type stack[SZ]; int top = -1, bottom = -1; bool push(my_type new_el) { if (top == SZ - 1) & return false; stack[++top] = new_el; return true; } my_type pop() { if (top >= 0) & return stack[top--]; } int main() { for(;;){ & char q; & int a; & cin >> q >> a; & if (q == '+') cout << push(a) << endl; & else if (q == '-') cout << pop() << endl; & else cout << top << endl; } return 0; }
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
C++
Comments
You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!
thanks guys. i really appreciate this. it was cool
Leave a comment