#include<iostream>
using namespace std;
class stackid
{
private:
int top;
int arr[5];
public:
stackid()
{
top=-1;
for(int i=0;i<5;i++)
{
arr[i]=0;
}
}
void Push()
{
int pu;
if(top==4)
{
cout<<"Queue is Full:"<<endl;
}
else
{
cout<<"-------------------------"<<endl;
cout<<"Enter element in stack:";
cin>>pu;
cout<<"-------------------------"<<endl;
top++;
arr[top]=pu;
}
}
void pop()
{
if(top==-1)
{
cout<<"Queue is already empty"<<endl;
}
else
{
cout<<"-----------------------------------------"<<endl;
cout<<"element deleted from stack is:"<<arr[top]<<endl;
cout<<"-----------------------------------------"<<endl;
top--;
}
}
void display()
{
for(int i=0;i<5;i++)
{
cout<<arr[top]<<" ";
cout<<endl;
top--;
}
}
};
int main()
{
stackid obj;
cout<<"\t1.Push"<<endl;
cout<<"\t2.pop"<<endl;
cout<<"\t3.display"<<endl;
int c;
while(true)
{
cout<<"please enter your choice:";
cin>>c;
switch(c)
{
case 1:
obj.Push();
break;
case 2:
obj.pop();
break;
case 3:
obj.display();
break;
default:
cout<<"wrong choice:"<<endl;
break;
}
}
}
No comments:
Post a Comment