#include "pqueue.h"

class PriorityQueue<ValueType>

This class models a linear structure called a priority queue in which values are processed in order of priority. As in conventional English usage, lower priority numbers correspond to higher effective priorities, so that a priority 1 item takes precedence over a priority 2 item.
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.

Constructor detail


PriorityQueue();
Initializes a new priority queue, which is initially empty.

Usage:

PriorityQueue<ValueType> pq;

Method detail


int size();
Returns the number of values in the priority queue.

Usage:

int n = pq.size();

bool isEmpty();
Returns true if the priority queue contains no elements.

Usage:

if (pq.isEmpty()) . . .

void clear();
Removes all elements from the priority queue.

Usage:

pq.clear();

void enqueue(ValueType value, double priority);
Adds 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();
Removes and returns the highest priority value. If multiple entries in the queue have the same priority, those values are dequeued in the same order in which they were enqueued.

Usage:

ValueType first = pq.dequeue();

ValueType peek();
Returns the value of highest priority in the queue, without removing it.

Usage:

ValueType first = pq.peek();