#include<iostream>
using namespace std;
const int size=5;
class stack
{
private:
int top,q[size],data;
public:
stack()
{
top=-1;
}
void push()
{
if(top==size-1)
{
cout<<"stack overflow"<<endl;
}
else
{
cout<<"enter the data into the stack:";
cin>>q[++top];
push();
}
}
void pop()
{
if(top==-1)
{
cout<<"stack underflow"<<endl;
}
else{
data=q[top];
q[top]==NULL;
cout<<"the deleted data is:"<<data<<endl;
top--;
pop();
}
}
void display()
{
cout<<"data in the stack:"<<endl;
for(int i=0;i=4;i++)
{
cout<<q[i]<<endl;
}
}
};
int main()
{
stack s1;
s1.push();
s1.display();
s1.pop();
return 0;
}
0 comments:
Post a Comment