#ifndef PRIORITY_QUEUE_H #define PRIORITY_QUEUE_H #include "BinaryTree.h" #include "VariousExceptions.h" template class PriorityQueue { public: // constructor PriorityQueue(); // number of elements int size() const; // is the queue empty? bool isEmpty() const; // insert (key,element) into queue void insertItem(const Key& k, const Element& e); // return element with minimum key Element& minElement() throw(EmptyContainerException); // return minimum key const Key& minKey() const throw(EmptyContainerException); // remove minimum (element,key) entry void removeMin() throw(EmptyContainerException); //////////////////////////////////////////////////////////////////////// // Nothing from this point on is public. Read at your own risk. //////////////////////////////////////////////////////////////////////// class Item { // a (key, element) pair private: Key _key; // key value Element _elem; // element public: Item(const Key& k = Key(), const Element& e = Element()) : _key(k), _elem(e) { } // constructor const Key& key() const // gets the key (read only) { return _key; } Element& element() // gets the element { return _elem; } const Element& element() const // gets the element (read only) { return _elem; } void setKey(const Key& k) // sets the key value { _key = k; } void setElement(const Element& e) // sets the element { _elem = e; } }; // typedef Item Item; // (key, element) pair typedef BinaryTree Tree; typedef typename Tree::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 Tree T; // heap tree Comp comp; // comparator Position findNode(int place); // find node at given place Position add(Item it); // adds new node and returns position Item remove(); // remove last internal node and return item }; #include "PriorityQueue.tcc" #endif