Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <iostream>
- using namespace std;
- struct stack {
- int top=0;
- int arr[100];
- void push( int num ) {
- if( top<100 ) arr[top++] = num;
- else cout << "Stack Overflow" << endl;
- }
- int pop() {
- if( top ) return arr[--top];
- else {
- cout << "Stack Underflow" << endl;
- return -1;
- }
- }
- };
- int main() {
- struct stack int_stack;
- int cmd, num;
- cout << "1 - push\n2 - pop\n0 - Quit" << endl;
- while( true ) {
- cout << "cmd: ";
- cin>>cmd;
- if( !cmd ) break;
- switch(cmd) {
- case 1:
- cout << "Push: ";
- cin>> num;
- int_stack.push(num);
- break;
- case 2:
- cout << "Pop: ";
- num = int_stack.pop();
- if( num!=-1 ) cout << num << endl;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement