/* * File: stack.h * A template class definition for a Stack ADT * using a linked-list representation * * From Dr. Mateen Rizki * * Modified: spc * * DESCRIPTION: stack is a stack of objects * The template parameter Stack_entry is the type of items contained. * * OPERATIONS: * stack() * Post: Initializes an empty stack. * * push(const Stack_entry& item) * Pre: none * Post: copy of item has been pushed onto the stack * * pop() * Pre: top_node != NULL * Post: top item of the stack has been removed * * Stack_entry top() * Precondition: top_node != NULL * Postcondition: top item of the stack is returned and stack unchanged; * throws exception if stack is empty * * empty() * Postcondition: Returns true if stack empty, false otherwise * * SEMANTICS: * This class has reference semantics. */ #ifndef _STACK #define _STACK #include using namespace std; template class stack { public: class node { public: Stack_entry data; node *next; }; stack(); bool empty() const; void pop(); Stack_entry top() const; void push(const Stack_entry&); private: node *top_node; }; #endif