/////////////////////mydefs2b.h//////////////// class node { // class node outside Istack, needs friend friend class Istack; int data; node* next; node(int, node* ); // builder-initializer prototype }; 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(); // Not defined here, later bool isempty() { return( top == NULL ); } bool isfull() { return( FALSE ); } // Never Full }; ////////////////////////stack2b.cc///////////// #include // Linked list implementation of stacks. node :: node(int d, node* n) { data = d; next = n; } int Istack :: 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; } /////////////////////stackmain2b.cc////////// #include void 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 */