#include "conio.h"
const int SIZE = 10;
template
class stack
{
StackType stck[SIZE];
int tos;
public:
stack() {
tos = 0;
}
void push(StackType ob)
{
if(tos==SIZE) {
cout << "Stack is full.\n";
return;
}
stck[tos] = ob;
tos++;
}
StackType pop()
{
if(tos==0) {
cout << "Stack is empty.\n";
return 0; // return null on empty stack
}
tos--;
return stck[tos];
}
};
int main()
{
int i,j;
stack
clrscr();
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: " << s1.pop() << "\n";
for(j=0; j<3; j++)
cout << "Pop s2: " << s2.pop() << "\n";
stack
ds1.push(1.1);
ds2.push(2.2);
ds1.push(3.3);
ds2.push(4.4);
ds1.push(5.5);
ds2.push(6.6);
for(i=0; i<3; i++)
cout << "Pop ds1: " << ds1.pop() << "\n";
for(j=0; j<3; j++)
cout << "Pop ds2: " << ds2.pop() << "\n";
getch();
return 0;
}
No comments:
Post a Comment