#include #include class Istack { int sz; int top; int* stack; public: // member function prototypes void init(int ); void push(int ); int pop(); bool isempty(); bool isfull(); }; /* class Pstack { class node { public: int data; node* next; }; node* new_node(int , node* ); node* top; public: // Note that the stack is implicit void init(int nitems ); void push(int x); int pop(); bool isempty(); bool isfull(); }; */ // Array implementation of stacks. // Grow from high index towards 0. void Istack :: init(int nitems = 100) { sz = nitems; stack = new int[sz]; top = sz; } void Istack :: push(int x) { assert( !isfull() ); stack[--top] = x; } int Istack :: pop() { assert( !isempty() ); return( stack[top++] ); } bool Istack :: isempty() { return( top == sz ); } bool Istack :: isfull() { return( top == 0 ); } main() { Istack s1, s2; int i; s1.init(500); s2.init(); for( i = 0; i < 20; i++ ) { s1.push(i); } for( i = 0; i < 20; i++ ) { cout << s1.pop() << ' '; } cout << endl; s2.push(10); i = s2.pop(); }