------------------------------------------------------------------------------
MC logo
Generalized Stack Implementation
[^] Code Examples
------------------------------------------------------------------------------
<<Generalized Stack Class genstack.cc Generalized Stack Driver>>
#include "genstack.h"

using namespace std;

// Pop the stack.
Stack_Elt *Stack::pop() {
        if(head == 0) return 0;                 // Take care of empty.

        Node *zombie = head;                    // Save list head.
        head = head->next;                      // Advance the list head.
        Stack_Elt *retval = zombie->data;       // Remember data.
        delete zombie;                          // Free the old node.

        return retval;
}

// Print the stack contents.
void Stack::print(ostream &strm) const
{
        strm << "[<";
        for(Node *n = head; n != 0; n = n->next) {
                strm << " ";
                n->data->print(strm);
        }
        strm << " <]";
}
<<Generalized Stack Class Generalized Stack Driver>>