//C++ Program to perform STACK
Operations.
#include<iostream.h>
#include<conio.h>
class stack
{
int s[10],n,i,size,t,ele,x;
public:
void create();
void push();
void pop();
void dis();
};
void stack::create()
{
cout<<"\n";
cout<<"Enter the size of
the stack : ";
cin>>size;
t=0;
}
void stack::push()
{
if(t<size)
{
cout<<"\n";
cout<<"Enter the elemnet
: ";
cin>>x;
s[t]=x;
t=t+1;
}
else
{
cout<<"\n";
cout<<"The stack is
overflow : ";
}
}
void stack::pop()
{
if(size==0)
{
cout<<"\n";
cout<<"The stack is
underflow : ";
}
else
{
ele=s[t];
t=t-1;
cout<<"\n";
cout<<"Deleted elemnet
are : "<<s[t];
}
}
void stack::dis()
{
cout<<"\n";
cout<<"STACk ";
for(i=t-1;i>=0;i--)
if(i==t-1)
{
cout<<"\n \t
|"<<s[i]<<"|<--- Top \n";
cout<<" \t ______ \t
";
}
else
{
cout<<"\n \t | "
<<s[i]<<"| \n";
cout<<" \t ______ \t
";
}
}
void main()
{
int ch,a,t,b;
stack c;
clrscr();
do
{
cout<<"\n";
cout<<"\t STACK
OPERATIONS \n";
cout<<"\t
~~~~~~~~~~~~~~~~ \n";
cout<<"* CREATE
"<<endl;
cout<<"* PUSH
"<<endl;
cout<<"* POP
"<<endl;
cout<<"\n";
cout<<"Entter your choice
: ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n";
cout<<"\t
1.CREATE \n";
cout<<"\t
~~~~~~~~ \n";
cout<<"\n";
cout<<"Empty
stack is Created ";
c.create
();
break;
case 2:
cout<<"\n";
cout<<"\t
2.PUSH \n";
cout<<"\t
~~~~~~~ \n";
c.push();
c.dis();
break;
case 3:
cout<<"\n";
cout<<"\t
3.POP \n";
cout<<"\t
~~~~~ \n";
c.pop();
c.dis();
break;
}
cout<<"\n";
cout<<"Do u want continue
Press 1 :";
cin>>b;
}while (b!=0);
getch();
}
No comments:
Post a Comment