#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int top=-1;
class mohan
{
public:
int s[10];
void push(int);
void pop();
void display();
};
void mohan::push(int n)
{
if(top>=n-1)
cout<<"\n\tSTACK IS FULL";
else
{
top++;
cout<<"\n\tEnter d element to push";
cin>>s[top];
}
}
void mohan::pop()
{
if(top==-1)
cout<<"\n\t STACK IS EMPTY";
else
{
cout<<"\n\tDeleted Element is:"<<s[top];
top--;
}
}
void mohan::display()
{
if(top==-1)
cout<<"\n\t STACK IS EMPTY";
else
{
cout<<"\n\t Elements are";
for(int i=top;i>=0;i--)
cout<<"\t"<<s[i];
}
}
void main()
{
clrscr();
int ch,n;
mohan m;
cout<<"\n\t STACK OPERATION";
cout<<"\n \t 1.push \n\t 2.pop \n\t 3.display \n\t 4.Exit";
cout<<"\n\n\t How many Element do u want";
cin>>n;
do
{
cout<<"\n\t Enter ur choice";
cin>>ch;
switch(ch)
{
case 1:
m.push(n);break;
case 2:
m.pop();break;
case 3:
m.display();break;
case 4:
exit(0);
default:
cout<<"\n\t Choose Correct choice";
}
}while(ch!=4);
getch();
}
Comments
Post a Comment