#include ////////////////////////mydefs1b.cc//////////// class Istack { int sz; int top; int* stack; public: void init(int Nitems = 100) { sz = Nitems; stack = new int[sz]; top = sz; } void push(int x) { assert( !isfull() ); stack[--top] = x; } int pop() { assert( !isempty() ); return( stack[top++] ); } bool isempty() { return(( top == sz )); } bool isfull() { return(( top == 0)); } }; class Cstack { // Changed int sz; int top; char* stack; // Changed public: // init, push, and pop are changed void init(int Nitems = 100) { sz = Nitems; stack = new char[sz]; top = sz; } void push(char x) { assert( !isfull() ); stack[--top] = x; } char pop() { assert( !isempty() ); return( stack[top++] ); } bool isempty() { return(( top == sz )); } bool isfull() { return(( top == 0)); } }; ////////////////////////stackmain1b.cc////////////// #include void main() { Istack s1; // a stack of integers Cstack s3; // a stack of chars int i; s1.init(500); s3.init(); // default size of 100 for( i = 0; i < 20; i++ ) { s1.push(i); // also push(s1, i); } for( i = 0; i < 20; i++ ) { cout << s1.pop() << ' '; } cout << endl; for( i = 0; i < 20; i++ ) { s3.push('a' + i); // overloading push } for( i = 0; i < 20; i++ ) { cout << s3.pop() << ' '; } cout << endl; } /* 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 t s r q p o n m l k j i h g f e d c b a */