#include<iostream.h>
#include<conio.h>
class stack
{
int top,st[20];
public:
stack()
{
top=-1;
}
void push(int a)
{
st[++top]=a;
}
int pop()
{
return st[top--];
}
void display();
};
void stack::display() //inline function
{
for(int i=top;i>=0;i--)
{
cout<<"\n"<<st[i];
}
}
void main()
{
stack s;
int a,z,data,x;
clrscr();
do
{
cout<<"1.push 2.pop 3.display:";
cin>>a;
switch(a)
{
case 1:cout<<"enter the data to push.";
cin>>data;
s.push(data);break;
case 2:x=s.pop();
cout<<"popped element is:"<<x;break;
case 3:s.display();
}
cout<<"continue 1.yes 2.no";
cin>>z;
}while(z!=2);
getch();
}
STACK OPERATIONS |
class stack
{
int top,st[20];
public:
stack()
{
top=-1;
}
void push(int a)
{
st[++top]=a;
}
int pop()
{
return st[top--];
}
void display();
};
void stack::display() //inline function
{
for(int i=top;i>=0;i--)
{
cout<<"\n"<<st[i];
}
}
void main()
{
stack s;
int a,z,data,x;
clrscr();
do
{
cout<<"1.push 2.pop 3.display:";
cin>>a;
switch(a)
{
case 1:cout<<"enter the data to push.";
cin>>data;
s.push(data);break;
case 2:x=s.pop();
cout<<"popped element is:"<<x;break;
case 3:s.display();
}
cout<<"continue 1.yes 2.no";
cin>>z;
}while(z!=2);
getch();
}
No comments:
Post a Comment