PROGRAM:
#include<iostream.h>
#include<conio.h>
#define MAX 20
class stack
{
private:
int s[MAX];
int top,item;
public:
stack()
{
top=-1;
}
void push()
{
if(top==MAX-1)
{
cout<<"Stack is full"<<endl;
}
else
{
cout<<"Enter the item"<<endl;
cin>>item;
top++;
s[top]=item;
}
}
void pop()
{
if(top==-1)
{
cout<<"Stack is empty"<<endl;
}
else
{
cout<<"Item deleted is:"<<s[top]<<endl;
item=s[top];
top--;
}
}
void display()
{
int i;
if(top==-1)
{
cout<<"Stack is empty";
}
else
{
cout<<"items are:"<<endl;
for(i=0;i<=top;i++)
{
cout<<s[i]<<endl;
}
}
}
};
void main()
{
clrscr();
int ch;
stack s1;
do
{
cout<<"Enter your Choice: 1.push 2.pop 3.display 4.exit"<<endl;
cin>>ch ;
switch(ch)
{
case 1: s1.push();
break;
case 2: s1.pop();
break;
case 3: s1.display();
break;
}
}
while(ch<=3);
getch();
}
//for any errors pls comment.......
Login Your exness login Account To Read The Latest News About The Platform.s
ReplyDelete