Class: PriorityQueue

PriorityQueue(typeopt, comparatoropt)

Priority Queue

Constructor

new PriorityQueue(typeopt, comparatoropt)

Parameters:
Name Type Attributes Description
type string <optional>
(min|max|custom) - default min. If custom {comparator} should be provided
comparator function <optional>
Custom comparator function. E.g. (a,b) => a.priority - b.priority
Source:

Members

isEmpty

Returns true/false if PQ is empty
Source:

peek

Peek heap element
Source:

size

Returns number of elements
Source:

Methods

add(val)

Add a new value to the queue
Parameters:
Name Type Description
val any
Source:

clear()

Clears the PQ
Source:

contains(val) → {boolean}

Returns true/false if PQ contains certain value among its entries,
Parameters:
Name Type Description
val any The value to search for.
Source:
Returns:
Type
boolean

poll() → {any}

Retrieves and remove element with the highest priority
Source:
Returns:
element
Type
any

toArray() → {Array}

Converts and return an array from stack
Source:
Returns:
Type
Array