Source of Listing7-3.h


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

  4: /** ADT stack: Link-based implementation.
  5:     Listing 7-3.
  6:     @file LinkedStack.h */
  7:  
  8: #ifndef LINKED_STACK_
  9: #define LINKED_STACK_

 11: #include "StackInterface.h"
 12: #include "Node.h"

 14: template<class ItemType>
 15: class LinkedStack : public StackInterface<ItemType>
 16: {
 17: private:
 18:         Node<ItemType>* topPtr; // Pointer to first node in the chain;
 19:                            // this node contains the stack's top

 21: public:
 22: // Constructors and destructor:
 23:         LinkedStack();                                   // Default constructor
 24:    LinkedStack(const LinkedStack<ItemType>& aStack);// Copy constructor 
 25:         virtual ~LinkedStack();                          // Destructor
 26:         
 27: // Stack operations:
 28:         bool isEmpty() const;
 29:         bool push(const ItemType& newItem);
 30:         bool pop();
 31:         ItemType peek() const;
 32: }; // end LinkedStack

 34: #include "LinkedStack.cpp"
 35: #endif