Code:
#include<iostream.h>
void push(int stack[], int &top)
{
int element;
if (top==4)
cout<<""<<endl;
else
{
cout<<"enter element to puch in stack===="<<endl;
cin>>element;
top++;
stack[top]=element;
}
}
void pop(int stack[],int &top)
{
if (top==-1)
cout<<"stack is empty"<<endl;
else
{
cout<<"poped element of stack is===="<<stack[top]<<endl;
top--;
}
}
void show(int stack[], int &top)
{
for (int i=top;i>=0;i--)
cout<<stack[i]<<endl;
}
void main()
{
char opt='y';
int stack[5];
int top=-1;
while (opt=='y')
{
cout<<"enter 'P' for PUSH"<<endl<<"enter 'O' for POP"<<endl<<"enter 'S' for SHOW"<<endl;
cin>>opt;
if (opt=='p')
push(stack,top);
else
if (opt=='o')
pop(stack,top);
else
if (opt=='s')
show(stack,top);
else
cout<<"you have entered werong character"<<endl;
cout<<"DO you want more y/n"<<endl;
cin>>opt;
}//end of while
}// end of main