PriorityQueue

PriorityQueue

Priority Queue Representation

Constructor

new PriorityQueue()

Example
const pq = new Collections.PriorityQueue();
// FOR ALL EXAMPLES BELOW. ASSUME pq IS CLEARED BEFORE EACH EXAMPLE

Methods

clear() → {undefined}

Removes all elements from the PriorityQueue
Returns:
Type
undefined

dequeue() → {*}

Removes The element with the lowest priority from the queue
Returns:
The element with the lowest priority in the queue pq.dequeue() // from the example above, this operation returns "wakeup", then "wash dishes" on second dequeue
Type
*

enqueue(data, priority)

Inserts given data into queue with a certain priority Lower numbers are removed from queue first.
Example
pq.enqueue("wakeup", 1);
pq.enqueue("wash dishes", 2);
Parameters:
Name Type Description
data number The data to queue
priority priority The relative Importance of @param data to othe data in the queue

size() → {number}

Reports the size of the priorityqueue
Returns:
The size of the queue
Type
number