You are on page 1of 2

#include<iostream.

h>
#include<conio.h>
#define SIZE 5
class stack
{
int a[SIZE];
int top;
public:
stack()
{
top=-1;
}
void push();
void pop();
void display();
};

void stack::push()
{
if(top>SIZE-1)
{
cout<<"Stack over ;
}
else
{
top++;
cin>>a[top];
}
}
void stack::pop()
{
if(top<=-1)
{
cout<<"STACK OVERFLOW";
}
else
{
top-
}
void stack::display()
{
for(int i=top;i>=0;i--)
cout<<a[i]<<endl;
}
void main()
{
clrscr();
stack s;
int x;
do
{
cout<<"1 to pushpa\n2 to pop\n3 to display\n4 to exit";
cin>>x;
switch(x)
{
case 1:
s.push();
break;
case 2:
s.pop();
break;
case 3:
s.display();
break;
}
}
while(x>4);
getch();
}

You might also like