Source of ListQueue.cpp


  1: //  Created by Frank M. Carrano and Tim Henry.
  2: //  Copyright (c) 2013 __Pearson Education__. All rights reserved.

  4: /** ADT queue: ADT list implementation.
  5:  Listing 14-2.
  6:  @file ListQueue.cpp */

  8: #include "ListQueue.h"  // header file

 10: template<class ItemType>
 11: ListQueue<ItemType>::ListQueue()
 12: {
 13:    listPtr = new LinkedList<ItemType>();
 14: }  // end default constructor

 16: template<class ItemType>
 17: ListQueue<ItemType>::ListQueue(const ListQueue& aQueue) : listPtr(aQueue.listPtr)
 18: {
 19: }  // end copy constructor

 21: template<class ItemType>
 22: ListQueue<ItemType>::~ListQueue()
 23: {
 24: }  // end destructor

 26: template<class ItemType>
 27: bool ListQueue<ItemType>::isEmpty() const
 28: {
 29:    return listPtr->isEmpty();
 30: }  // end isEmpty

 32: template<class ItemType>
 33: bool ListQueue<ItemType>::enqueue(const ItemType& newEntry)
 34: {
 35:    return listPtr->insert(listPtr->getLength() + 1, newEntry);
 36: }  // end enqueue

 38: template<class ItemType>
 39: bool ListQueue<ItemType>::dequeue()
 40: {
 41:    return listPtr->remove(1);
 42: }  // end dequeue

 44: template<class ItemType>
 45: ItemType ListQueue<ItemType>::peekFront() const throw(PrecondViolatedExcep)
 46: {
 47:    if (isEmpty())
 48:       throw PrecondViolatedExcep("peekFront() called with empty queue.");

 50:    // Queue is not empty; return front
 51:    return listPtr->getEntry(1);
 52: }  // end peekFront
 53: // End of implementation file.