class PriorityQueue<ValueType>| Constructor | |
| PriorityQueue() | Initializes a new priority queue, which is initially empty. |
| Methods | |
| size() | Returns the number of values in the priority queue. |
| isEmpty() | Returns true if the priority queue contains no elements. |
| clear() | Removes all elements from the priority queue. |
| enqueue(value, priority) | Adds value to the queue with the specified priority. |
| dequeue() | Removes and returns the highest priority value. |
| peek() | Returns the value of highest priority in the queue, without removing it. |
PriorityQueue();
Usage:
PriorityQueue<ValueType> pq;
int size();
Usage:
int n = pq.size();
bool isEmpty();
true if the priority queue contains no elements.
Usage:
if (pq.isEmpty()) . . .
void clear();
Usage:
pq.clear();
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.
Usage:
pq.enqueue(value, priority);
ValueType dequeue();
Usage:
ValueType first = pq.dequeue();
ValueType peek();
Usage:
ValueType first = pq.peek();