# include <iostream.h> # include <conio.h> # include <process.h> class stack { int arr[50]; int top; public: int get_top(); stack() { top=-1; } void push(int); int pop(); void peep(); }; int display_menu(); int stack :: get_top() { return(top); } void stack :: push(int no) { arr[top+1]=no; top=top+1; } int stack :: pop() { int no; if(top<0) { return(NULL); } else { no=arr[top]; top=top-1; return(no); } } void stack :: peep() { if(top>=0) { for(int i=top;i>=0;i--) { cout<<\"Stack [\"<<i<<\"] :\"<<arr[i]<<endl; } } else { cout<<\"Empty Stack !!!\"<<endl; } } void main() { stack s1; while(1) { switch(display_menu()) { case 1: cout<<\"Enter Number to push :\"; int no; cin>>no; s1.push(no); s1.peep(); getch(); break; case 2: no=s1.pop(); if(no!=NULL) { cout<<\"Stack [\"<<s1.get_top()+1<<\"] :\"<<no; } else { cout<<\"Empty Stack !!!\"<<endl; } getch(); break; case 3: s1.peep(); getch(); break; case 4: exit(1); } } } int display_menu() { clrscr(); int ch; cout<<endl; cout<<\"\\t\\t\\t| 1 | : PUSH\"<<endl; cout<<\"\\t\\t\\t| 2 | : POP\"<<endl; cout<<\"\\t\\t\\t| 3 | : PEEP\"<<endl; cout<<\"\\t\\t\\t| 4 | : Exit\"<<endl; cout<<\"\\t\\t\\tEnter Your Choice :\"; cin>>ch; return(ch); }