#include #include ////////////////////////mydefs2.h///////////////// class node { friend class Istack; int data; node* next; node(int d, node* n) { data = d; next = n; } // builder and initializer of node }; class Istack { // linked list implementation node* top; public: void init(int Nitems = 100) { top = NULL; } void push(int x) { top = new node(x, top); } int pop() { assert( !isempty() ); int temp = top -> data; // get data node* oldtop = top; // point to old top = top -> next; // unlink old delete oldtop; // discard return temp; } bool isempty() { return( top == NULL ); } bool isfull() { return( FALSE ); } // Never Full }; ////////////////////////stackmain2.cc///////// 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(); } /* 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 */