class PriorityQueue<ValueType>
Constructor  
O(1)  Initializes a new priority queue, which is initially empty.  
Methods  
O(1)  Returns the last value in the queue by reference.  
O(N)  Adjusts an existing value in the queue to have a new specified priority.  
O(1)  Removes all elements from the priority queue.  
O(log N)  Removes and returns the highest priority value.  
O(log N)  Adds value to the queue with the specified priority. 

O(N log N)  Returns true if the two queues contain the same elements with the same priorities. 

O(1)  Returns the first value in the queue by reference.  
O(1)  Returns true if the priority queue contains no elements. 

O(1)  Returns the value of highest priority in the queue, without removing it.  
O(1)  Returns the priority of the first element in the queue, without removing it.  
O(1)  Returns the number of values in the priority queue.  
O(N)  Converts the queue to a printable string representation.  
Operators  
O(N log N)  Returns true if pq1 and pq2 contain the same elements. 

O(N log N)  Returns true if pq1 and pq2 are different. 

O(N)  Outputs the contents of the queue to the given output stream.  
O(N log N)  Reads the contents of the given input stream into the queue. 
PriorityQueue();
Usage:
PriorityQueue<ValueType> pq;
ValueType& back();
This function throws an error if the queue is empty.
Usage:
ValueType last = pq.back();
void changePriority(ValueType value, double newPriority);
value
in the queue to now have the specified new priority,
which must be at least as urgent as (≤) that value's previous
priority in the queue.
This function throws an error if the element value is not present in the queue, if the new priority passed is not at least as urgent as its current priority, or if NaN (notanumber) is passed as the priority.
Usage:
pq.changePriority(value, newPriority);
void clear();
Usage:
pq.clear();
ValueType dequeue();
This function throws an error if the queue is empty.
Usage:
ValueType first = pq.dequeue();
void enqueue(ValueType value, double priority);
value
to the queue with the specified priority.
Lower priority numbers correspond to higher priorities, which
means that all priority 1 elements are dequeued before any
priority 2 elements.
Negative priorities are allowed and are not treated differently from other values. That is, a priority of 1 comes before one of 0, which comes before 1, 2, 3, etc.
This function throws an error if NaN (notanumber) is passed as the priority.
Usage:
pq.enqueue(value, priority);
bool equals(const PriorityQueue& pq) const;
true
if the two queues contain exactly the same element values with the same priorities.
Identical in behavior to the ==
operator.
Usage:
if (pq.equals(pq2)) ...
ValueType& front();
This function throws an error if the queue is empty.
Usage:
ValueType first = pq.front();
bool isEmpty() const;
true
if the priority queue contains no elements.
Usage:
if (pq.isEmpty()) ...
ValueType peek() const;
This function throws an error if the queue is empty.
Usage:
ValueType first = pq.peek();
double peekPriority() const;
This function throws an error if the queue is empty.
Usage:
double priority = pq.peekPriority();
int size() const;
Usage:
int n = pq.size();
string toString() const;
"{pri1:value1, pri2:value2, pri3:value3}"
If your project sets the compiler flag PQUEUE_PRINT_IN_HEAP_ORDER
, the elements are shown in an unpredictable order.
If not, they are listed in increasing order of priority.
Usage:
string str = pq.toString();