Source of Listing14-1.h


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

  4: // Listing 14-1.

  6: /** ADT queue: ADT list implementation.
  7:  @file ListQueue.h */
  8: #ifndef LIST_QUEUE_
  9: #define LIST_QUEUE_
 10: #include "QueueInterface.h"
 11: #include "LinkedList.h"
 12: #include "PrecondViolatedExcept.h"
 13: #include <memory>

 15: template<class ItemType>
 16: class ListQueue : public QueueInterface<ItemType>
 17: {
 18: private:
 19:    std::unique_ptr<LinkedList<ItemType>> listPtr; // Pointer to list of queue items
 20: public:
 21:    ListQueue();
 22:    ListQueue(const ListQueue& aQueue);
 23:    ~ListQueue();
 24:    
 25:    bool isEmpty() const;
 26:    bool enqueue(const ItemType& newEntry);
 27:    bool dequeue();
 28:    
 29:    /** @throw  PrecondViolatedExcept if this queue is empty. */
 30:    ItemType peekFront() const throw(PrecondViolatedExcept);
 31: }; // end ListQueue
 32: #include "ListQueue.cpp"
 33: #endif