PriorityQueue

PriorityQueue

Class representing priority queue.
Use Array as container.

Constructor

new PriorityQueue(compare, otherPriorityQueue)

Version:
  • v1.0

Create a prioirty queue.

Parameters:
Name Type Default Description
compare function

inequality function, compare two element and return true or false.

otherPriorityQueue PriorityQueue null

priority queue for deep copy.

Methods

compareFunction() → {function}

Get the compare function of priority queue.

Returns:

compare function

Type
function

top() → {boolean|*}

Get the top element of priority queue.

Returns:

false if the priority queue is empty else top element.

Type
boolean | *

empty() → {boolean}

Make sure the priority queue is empty.

Returns:

let know the priority queue is empty.

Type
boolean

size() → {number}

Get the number of elements

Returns:

the number of elements

Type
number

clear()

Initialize priority queue

push(data)

Push new data into priority queue.

Parameters:
Name Type Description
data *

the element of priority queue.

pop() → {boolean}

pop the top element of priority queue.

Returns:

check well eliminated.

Type
boolean

toString() → {string}

show information of object

Returns:
Type
string

copy() → {PriorityQueue}

return a copy of this object.

Returns:
Type
PriorityQueue