#include<iostream.h>
#include<conio.h>
#include<process.h>
const int max=5;
class stack
{
int s[max];
int top;
int temp;
public:
stack (int j,int p){top=j;temp=p;}
void push(int item);
void pop();
void display();
};
void stack::push(int item)
{
if(top<4)
{
top++;
s[top]=item;
}
else
{
cout<<"\nStack is full!";
}
}
void stack::pop()
{
if(top>-1)
{
cout<<"\nThe popped item is "<<s[top];
top--;
}
else
{
cout<<"\nStack is empty!";
}
}
void stack::display()
{
temp=top;
if(temp==-1)
{
cout<<"\nStack is empty!" ;
}
else
{
while(temp>=0)
{
cout<<"\n"<<s[temp];
temp--;
}
}
}
void main()
{
clrscr();
stack x(-1,-1);
for(;;)
{
int ch,item;
cout<<"\nEnter->\n1:push 2:pop 3:display 4:exit:\t";
cin>>ch;
switch(ch)
{
case 1: cout<<"\nEnter the items:\t";
cin>>item;
x.push(item);
break;
case 2: x.pop();
break;
case 3: x.display();
break;
case 4: exit(0);
break;
}
}
}
jammy's 0 Newbie Poster
Salem 5,199 Posting Sage
Sci@phy 97 Posting Whiz in Training
chococrack 74 Junior Poster
Freaky_Chris 299 Master Poster
skatamatic 371 Practically a Posting Shark
chococrack 74 Junior Poster
iamthwee
Denniz 103 Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.