template <typename Key, typename Element, typename Comp>
class HeapPriorityQueue {
protected: // typename shortcuts
typedef Item<Key, Element> Item; // (key, element) pair
typedef VectorHeapTree<Item> HeapTree; // a heap of items
typedef HeapTree::Position Position; // a position in heap
protected: // local utilities
const Key& key(const Position& p) const // position's key
{ return p.element().key(); }
Element& element(const Position& p) // position's element
{ return p.element().element(); }
private: // member data
HeapTree T; // heap tree
Comp comp; // comparator
public:
HeapPriorityQueue(int capac = 100) // constructor
: T(capac), comp() { }
int size() const // number of elements
{ return (T.size()-1)/2; }
bool isEmpty() const // is the queue empty?
{ return size() == 0; }
void insertItem(const Key& k, const Element& e); // insert (key, element)
Element& minElement() // return min element
throw(EmptyContainerException) {
if (isEmpty())
throw EmptyContainerException("Minimum element of empty queue");
return element(T.root());
}
const Key& minKey() const // return minimum key
throw(EmptyContainerException) {
if (isEmpty())
throw EmptyContainerException("Minimum key of empty queue");
return key(T.root());
}
void removeMin() throw(EmptyContainerException); // remove minimum
};