Source of ArrayQueue.h


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

  4: /** ADT queue: Circular array-based implementation.
  5:  Listing 14-4.
  6:  @file ArrayQueue.h */

  8: #ifndef _ARRAY_QUEUE
  9: #define _ARRAY_QUEUE

 11: #include "QueueInterface.h"
 12: #include "PrecondViolatedExcep.h"

 14: const int MAX_QUEUE = 50;

 16: template<class ItemType>
 17: class ArrayQueue : public QueueInterface<ItemType>
 18: {
 19: private:
 20:    ItemType items[MAX_QUEUE]; // Array of queue items
 21:    int front;                 // Index to front of queue
 22:    int back;                  // Index to back of queue
 23:    int count;                 // Number of items currently in the queue
 24:    
 25: public:
 26:    ArrayQueue();
 27:    // Copy constructor and destructor supplied by compiler
 28:    bool isEmpty() const;
 29:    bool enqueue(const ItemType& newEntry);
 30:    bool dequeue();
 31:    
 32:    /** @throw PrecondViolatedExcep if queue is empty. */
 33:    ItemType peekFront() const throw(PrecondViolatedExcep);
 34: }; // end ArrayQueue
 35: #include "ArrayQueue.cpp"
 36: #endif