// ********************************************************* // Header file StackA.h for the ADT stack. // Array-based implementation. // ********************************************************* #include "Object.h" #include "StackException.h" const int MAX_STACK = 100; class Stack { public: // constructors and destructor: Stack(); // default constructor // copy constructor is supplied by the compiler ~Stack(); // stack operations: bool isEmpty() const; // Determines whether a stack is empty. // Precondition: None. // Postcondition: Returns true if the stack is empty; // otherwise returns false. void push(Object* newItem) throw(StackException); // Adds an item to the top of a stack. // Precondition: newItem is the item to be added. // Postcondition: If the insertion is successful, newItem // is on the top of the stack. // Exception: Throws StackException if the item cannot // be placed on the stack. Object* pop() throw(StackException); // Retrieves and removes the top of a stack. // Precondition: None. // Postcondition: If the stack is not empty, the item // that was added most recently is removed. However, if // the stack is empty, deletion is impossible. // Exception: Throws StackException if the stack is empty. void popAll(); // Removes all the items from the stack. // Precondition: None. // Postcondition: Stack is empty. Calls delete on all objects on the stack. const Object* peek() const throw(StackException); // Retrieves the top of a stack. // Precondition: None. // Postcondition: If the stack is not empty, stackTop // contains the item that was added most recently. // However, if the stack is empty, the operation fails // and stackTop is unchanged. The stack is unchanged. // Exception: Throws StackException if the stack is empty. private: Object* items[MAX_STACK]; // array of stack items int top; // index to top of stack }; // end class // End of header file.