// Simple Stack #ifndef STACK_H #define STACK_H #include "nodedata.h" //---------------------------------------------------------------------------- // class Stack // // ADT Stack: collection of zero or more items (list) with the restriction that // all insertions (push operation) and removals (pop operation) take // place at only one end, called the top of the stack (sometimes // called pushdown list, or LIFO -- Last In First Out) // // Assumptions: // -- assumes NodeData is a class of actual data // -- Node (linked list implementation) is a struct made of just // a NodeData* and a Node* // -- The push allocates memory for a Node, ptr to the data is passed in. // -- doesn't have to be NodeData* in stack, data may be stored directly // in the Node or array element, e.g. stack of ints, stack of NodeData //---------------------------------------------------------------------------- class Stack { friend ostream &operator<<(ostream&, const Stack&); public: Stack(); // default constructor ~Stack(); // destructor Stack(const Stack&); // copy constructor void clear(); // clear out, empty out stack bool isEmpty() const; // is stack empty? bool isFull() const; // is stack full? bool push(NodeData*); // insert item on stack bool pop(NodeData*&); // remove item from stack bool peek(NodeData*&) const; // retrieve item at stack top private: // for linked list implementation Node* top; // pointer to top of stack // for array implementation NodeData* array[MAX]; // assume MAX is defined int top; // subscript of stack top }; #endif