#include
#include
#define size 10
class stack
{
char stack[size];
int tos;
public:
void init();
void push(char ch);
char pop();
};
void stack::init()
{
tos=0;
}
void stack::push(char ch)
{
if(tos==size)
{
cout<<"Stack is full";
return;
}
stack[tos]=ch;
tos++;
}
char stack::pop()
{
if(tos==0)
{
cout<<"Stack is empty";
return 0;
}
tos--;
return stack[tos];
}
int main()
{
clrscr();
stack s1,s2;
int i;
s1.init();
s2.init();
s1.push('a');
s2.push('x');
s1.push('b');
s2.push('y');
s1.push('c');
s2.push('z');
for(i=0;i<3;i++) cout<<"pop s1: "<
return 0;
}
Output:
pop s1: c
pop s1: b
pop s1: a
pop s2: z
pop s2: y
pop s2: x
No comments:
Post a Comment