Source of Listing6-1.h


  1: //  Created by Frank M. Carrano and Timothy M. Henry.
  2: //  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

  4: /** @file StackInterface.h */

  6: #ifndef STACK_INTERFACE_
  7: #define STACK_INTERFACE_

  9: template<class ItemType>
 10: class StackInterface
 11: {
 12: public:
 13:    /** Sees whether this stack is empty.
 14:     @return  True if the stack is empty, or false if not. */
 15:    virtual bool isEmpty() const = 0;
 16:    
 17:    /** Adds a new entry to the top of this stack.
 18:     @post  If the operation was successful, newEntry is at the top of the stack.
 19:     @param newEntry  The object to be added as a new entry.
 20:     @return  True if the addition is successful or false if not. */
 21:    virtual bool push(const ItemType& newEntry) = 0;
 22:    
 23:    /** Removes the top of this stack.
 24:     @post  If the operation was successful, the top of the stack
 25:        has been removed.
 26:     @return  True if the removal is successful or false if not. */
 27:    virtual bool pop() = 0;
 28:    
 29:    /** Returns a copy of the top of this stack.
 30:     @pre  The stack is not empty.
 31:     @post  A copy of the top of the stack has been returned, and
 32:        the stack is unchanged.
 33:     @return  A copy of the top of the stack. */
 34:    virtual ItemType peek() const = 0;
 35:    
 36:    /** Destroys this stack and frees its assigned memory. */
 37:    virtual ~StackInterface() { }
 38: }; // end StackInterface
 39: #endif