///////////////////mydefs2a.h///////////// class Istack { // not array of ints but linked list of ints class node { public: int data; node* next; }; node* new_node(int , node* ); // prototype only node* top; public: // Note pop() is a prototype void init(int Nitems = 100) { top = NULL; } void push(int x) { top = new_node(x, top); } int pop(); // prototype function bool isempty() { return( top == NULL ); } bool isfull() { return( FALSE ); } }; //////////////////////////stackmain2a.cc///////// #include #include // Linked list implementation of stacks. Istack :: node* Istack :: new_node(int d, node* n) { node* t = new node; assert( t ); t -> data = d; t -> next = n; return( t ); } int Istack :: pop() { assert( !isempty() ); int t = top -> data; node* oldtop = top; top = top -> next; delete oldtop; return t; } 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 */