class LinkedQueue
1: // Created by Frank M. Carrano and Timothy M. Henry.
2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
4: // Listing 14-3.
6: /** ADT queue: Link-based implementation.
7: @file LinkedQueue.h */
8: #ifndef LINKED_QUEUE_
9: #define LINKED_QUEUE_
10: #include "QueueInterface.h"
11: #include "Node.h"
12: #include "PrecondViolatedExcept.h"
13: #include <memory>
15: template<class ItemType>
16: class LinkedQueue : public QueueInterface<ItemType>
17: {
18: private:
19: // The queue is implemented as a chain of linked nodes that has
20: // two external pointers, a head pointer for the front of the queue
21: // and a tail pointer for the back of the queue.
22: std::shared_ptr<Node<ItemType>> frontPtr;
23: std::shared_ptr<Node<ItemType>> backPtr;
24: public:
25: LinkedQueue();
26: LinkedQueue(const LinkedQueue& aQueue);
27: ~LinkedQueue();
28:
29: bool isEmpty() const;
30: bool enqueue(const ItemType& newEntry);
31: bool dequeue();
32:
33: /** @throw PrecondViolatedExcept if the queue is empty */
34: ItemType peekFront() const throw(PrecondViolatedExcept);
35: }; // end LinkedQueue
36: #include "LinkedQueue.cpp"