#include<iostream>
using namespace std;
int main()
{
int stack[20],top=-1,ch;
//MAX. SIZE IS 5.
while(1)
{
cout<<"PRESS 1 TO PUSH\nPRESS 2 TO POP\nPRESS 3 TO DISPLAY\nPRESS 4 TO EXIT\n";
cin>>ch;
switch(ch)
{
case 1: if(top==4)
cout<<"OVERFLOW\n";
else
{
cout<<"ENTER THE ELEMENT TO BE PUSHED:";
cin>>stack[++top];
}
break;
case 2:if(top==-1)
cout<<"UNDERFLOW\n";
else
cout<<"ELEMENT POPED:"<<stack[top--]<<endl;
break;
case 3: if(top==-1)
cout<<"EMPTY STACK\n";
else
{ for(int i=top;i>=0;i--)
cout<<stack[i]<<"\t";
cout<<endl;
}
break;
case 4 :break;
default:cout<<"INVALID ENTRY\n";
}//END OF SWITCH
if(ch==4)
break;
}//END OF WHILE
return(0);
}
No comments:
Post a Comment