1: // Created by Frank M. Carrano and Tim Henry. 2: // Copyright (c) 2013 __Pearson Education__. All rights reserved. 4: /** Heap-based implementation of the ADT priority queue. 5: Listing 17-4. 6: @file Heap_PriorityQueue.cpp */ 8: #include "Heap_PriorityQueue.h" 10: template<class ItemType> 11: Heap_PriorityQueue<ItemType>::Heap_PriorityQueue() 12: { 13: ArrayMaxHeap<ItemType>(); 14: } // end constructor 16: template<class ItemType> 17: bool Heap_PriorityQueue<ItemType>::isEmpty() const 18: { 19: return ArrayMaxHeap<ItemType>::isEmpty(); 20: } // end isEmpty 22: template<class ItemType> 23: bool Heap_PriorityQueue<ItemType>::add(const ItemType& newEntry) 24: { 25: return ArrayMaxHeap<ItemType>::add(newEntry); 26: } // end add 28: template<class ItemType> 29: bool Heap_PriorityQueue<ItemType>::remove() 30: { 31: return ArrayMaxHeap<ItemType>::remove(); 32: } // end remove 34: template<class ItemType> 35: ItemType Heap_PriorityQueue<ItemType>::peek() const throw(PrecondViolatedExcep) 36: { 37: try 38: { 39: return ArrayMaxHeap<ItemType>::peekTop(); 40: } 41: catch (PrecondViolatedExcep e) 42: { 43: throw PrecondViolatedExcep("Attempted peek into an empty priority queue."); 44: } // end try/catch 45: } // end peek