// Definition of class PQType, which represents the Priority Queue ADT class FullPQ{}; class EmptyPQ{}; #include "heap.h" template class PQType { public: PQType(int); // parameterized class constructor ~PQType(); // class destructor void MakeEmpty(); // Function: Initializes the queue to an empty state. // Post: Queue is empty. bool IsEmpty() const; // Function: Determines whether the queue is empty. // Post: Function value = (queue is empty) bool IsFull() const; // Function: Determines whether the queue is full. // Post: Function value = (queue is full) void Enqueue(ItemType newItem); // Function: Adds newItem to the rear of the queue. // Post: if (the priority queue is full) exception FullPQ is thrown; // else newItem is in the queue. void Dequeue(ItemType& item); // Function: Removes element with highest priority from the queue // and returns it in item. // Post: If (the priority queue is empty) exception EmptyPQ is thrown; // else highest priority element has been removed from queue. // item is a copy of removed element. private: int length; HeapType items; int maxItems; }; template PQType::PQType(int max) { maxItems = max; items.elements = new ItemType[max]; length = 0; } template void PQType::MakeEmpty() { length = 0; } template PQType::~PQType() { delete [] items.elements; } template void PQType::Dequeue(ItemType& item) // Post: element with highest priority has been removed // from the queue; a copy is returned in item. { if (length == 0) throw EmptyPQ(); else { item = items.elements[0]; items.elements[0] = items.elements[length-1]; length--; items.ReheapDown(0, length-1); } } template void PQType::Enqueue(ItemType newItem) // Post: newItem is in the queue. { if (length == maxItems) throw FullPQ(); else { length++; items.elements[length-1] = newItem; items.ReheapUp(0, length-1); } } template bool PQType::IsFull() const // Post: Returns true if the queue is full; false, otherwise. { return length == maxItems; } template bool PQType::IsEmpty() const // Post: Returns true if the queue is empty; false, otherwise. { return length == 0; }