///////////////////////////stack3.C/////////////// #include #include enum boolean {BAD, GOOD}; class Istack { class node { //linked list stack public: int data; node* next; }; node* new_node(int , node* ); node* top; public: // Note that Nitems is not used void init( int Nitems=100 ) { top = NULL; } void push(int x) {top = new_node(x, top); } int pop(); boolean isempty() { return ((top == NULL) ?BAD :GOOD); } boolean isfull() { return (BAD); } }; // Linked list implementation of stacks. Istack :: node* Istack :: new_node(int d, node* n) { node* t = new node; assert( t ); // space found OK t -> data = d; t -> next = n; return( t ); // return pointer to stack } int Istack :: pop() { assert( isempty() == GOOD); int t = top -> data; node* oldtop = top; top = top -> next; delete oldtop; // removes node that held return t; // data item being returned } 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(); }