#include
#include
//using namespace std;
#define max 5
//int top=-1;
template
class stack
{
t top;
t stack[max];
public:
stack()
{
top=-1;
}
void push(t x);
void pop();
void display();
};
void stack::push(t x)
{
if(top==(max-1))
{
cout<<"stack is overflow\n";
}
else
{
//cout<<"Enter an element to be pushed:";
//cin>>ob;
cout<<"pushed
element is=\n"<
stack[top]=x;
top=top+1;
}
}
void stack::pop()
{
if(top==NULL)
{
cout<<"stack is empty\n";
}
else
{
cout<<"popped element is\n";
top=top-1;
x=stack[top];
}
}
void stack::display()
{
int i;
for(i=top;i>0;i--)
{
cout<<"stack element is";
cout<<"\n"<
}
}
void main()
{
stack
s.push(20);
s.pop();
s.display();
getch();
}
Copyright © 2011 - All Rights Reserved - Softron.in
Template by Softron Technology