1: // Created by Frank M. Carrano and Timothy M. Henry.
2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
4: // Listing 14-2.
6: /** ADT queue: ADT list implementation.
7: @file ListQueue.cpp */
8: #include "ListQueue.h" // Header file
9: #include <memory>
11: template<class ItemType>
12: ListQueue<ItemType>::ListQueue()
13: : listPtr(std::make_unique<LinkedList<ItemType>>())
14: {
15: } // end default constructor
17: template<class ItemType>
18: ListQueue<ItemType>::ListQueue(const ListQueue& aQueue)
19: : listPtr(aQueue.listPtr)
20: {
21: } // end copy constructor
23: template<class ItemType>
24: ListQueue<ItemType>::~ListQueue()
25: {
26: } // end destructor
28: template<class ItemType>
29: bool ListQueue<ItemType>::isEmpty() const
30: {
31: return listPtr–>isEmpty();
32: } // end isEmpty
34: template<class ItemType>
35: bool ListQueue<ItemType>::enqueue(const ItemType& newEntry)
36: {
37: return listPtr–>insert(listPtr–>getLength() + 1, newEntry);
38: } // end enqueue
40: template<class ItemType>
41: bool ListQueue<ItemType>::dequeue()
42: {
43: return listPtr–>remove(1);
44: } // end dequeue
46: template<class ItemType>
47: ItemType ListQueue<ItemType>::peekFront() const throw(PrecondViolatedExcept)
48: {
49: if (isEmpty())
50: throw PrecondViolatedExcept("peekFront() called with empty queue.");
51:
52: // Queue is not empty; return front
53: return listPtr–>getEntry(1);
54: } // end peekFront
55: // end of implementation file