Class: PriorityQueue

PriorityQueue

A queue backed by a Binary Heap. Basic queue operation offer and poll run in O(lgn) time. The elements in this queue are ordered according to their natural ordering or based on the compare function provided. Reference: PriorityQueue in Oracle JDK

new PriorityQueue(compareFn)

Example -

var PriorityQueue = require("dsjslib").PriorityQueue
var pq=new PriorityQueue(function(w1,w2){
     return w1.weight - w2.weight;
})
Parameters:
Name Type Argument Description
compareFn userCompareFn <optional>

optional external ordering function for priority of elements

Source:

Methods

clear()

Cleanup and remove all elements from the queue

Source:

entries() → {Array}

Source:
Returns:

Returns array of elements in the queue. Ordering of those elements in undefined

Type
Array

offer(obj) → {PriorityQueue}

Parameters:
Name Type Description
obj

Insert the object in queue. Re-heapifies the queue.

Source:
Returns:

this

Type
PriorityQueue

peek() → {*}

Returns, without removing, the element at the head of the queue

Source:
Returns:

Returns the element at the head of the queue . The head of this queue is the maximum element with respect to the specified ordering. If multiple elements are tied for max value, the head is one of those elements -- ties are broken arbitrarily.

Type
*

poll() → {*}

Returns and removes the element at the head of the queue

Source:
Returns:

Returns and removes the element at the head of the queue . Re-heapifies the queue.. The head of this queue is the maximum element with respect to the specified ordering. If multiple elements are tied for max value, the head is one of those elements -- ties are broken arbitrarily.

Type
*

size() → {Number}

Source:
Returns:

number of elements in the queue

Type
Number