#include <iostream>
#include <conio>
#include <stdio>
#include <stdlib>
class stack
{
private:
int opt,i,top;
int arr[10];
public:
stack()
{ i=top=0;
}
void input()
{
while(1)
{
cout<<"\tpress 1 for push\n\tpress 2 for pop\n\tpress 3 for show stack\n\tpress 4 for exit\n";
cin>>opt;
switch(opt)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
show();
break;
case 4:
exit(0);
break;
}
}
}
void push()
{
if(top==10)
cout<<"stack is overflow\n";
else
{
top++;
cout<<"Enter element into the stack\t";
cin>>arr[top];
}
}
void pop()
{
if(top==0)
cout<<"stack is underflow\n";
else
{
cout<<"Has been poped"<<arr[top]<<endl;
top--;
}
}
void show()
{
cout<<"Your desire stack is\n";
for(i=1;i<=top;i++)
{
cout<<arr[i]<<endl;
}
}
};
void main()
{
stack s;
s.input();
getch() ;}
0 comments:
Post a Comment