Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std ;
- #define M 500
- class _stack
- {
- int arr[M], top ;
- public:
- _stack()
- {
- top = -1;
- };
- void push(int a)
- {
- if(top > M )
- {
- cout <<"overflow\n";
- return ;
- }
- top++;
- arr[top ] = a;
- cout << "Item inserted to stack : " << a << endl ;
- }
- void pop(void )
- {
- if(top == -1)
- {
- cout << "Underflow\n";
- return ;
- }
- cout<< "Deleting item : " << arr[top ] << endl;
- top-- ;
- }
- void _top(void )
- {
- if(top == -1 )
- cout << "Stack empty" << endl;
- else
- cout << "Stack top : " << arr[top ] << endl ;
- }
- };
- void input()
- {
- _stack stk ;
- int i, j,k ;
- while(1)
- {
- int choice, item ;
- cout << "delete(0 ) / insert (1) / show(3) / : " ;
- cin >> choice ;
- if(choice == 1)
- {
- cout <<"Enter item : ";
- cin >> item ;
- stk.push(item );
- }
- else if(choice == 0) stk.pop();
- else if(choice == 3) stk._top();
- cout <<"\n" << endl;
- }
- }
- int main()
- {
- input();
- /*
- _queue q ;
- stk.push(11);
- stk.push(12);
- stk.push(13);
- stk.front();
- stk.pop();
- stk.pop();
- stk.pop();
- stk.pop();
- */
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement