Constructor
new priorityQueue(value)
Example
var pq = new priorityQueue ();
var pq = new priorityQueue (“less”);
var pq = new priorityQueue (“greater”);
Parameters:
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value |
String | ORDER BY
Properties
|
Methods
(static) isEmpty() → {Boolean}
This method is used to check if this priority queue is empty.
Example
var pq = new priorityQueue ();
var ret1 = pq.isEmpty(); // ret1 = true
pq.push(1);
var ret2 = pq.isEmpty(); // ret2 = false
Returns:
This method returns ‘true’ if this priority queue is empty or ‘false’ if this priority queue is not empty.
- Type
- Boolean
(static) pop()
This method is used to remove the highest priority value from this priority queue.
Example
var pq1 = new priorityQueue ();
pq1.push(1);
pq1.push(2);
pq1.pop() // 2 will be removed.
var pq2 = new priorityQueue ("greater");
pq2.push(1);
pq2.push(2);
pq2.pop() // 1 will be removed
Throws:
This method returns null if this priority queue is empty.
(static) push(value)
This method is used to insert the specified value into this priority queue.
Example
var pq1 = new priorityQueue ();
pq1.push(1);
pq1.push(2);
var pq2 = new priorityQueue ();
pq2.push("A");
pq2.push("B");
Parameters:
| Name | Type | Description |
|---|---|---|
value |
Undefined | The value to be inserted to this priority queue. |
Throws:
This method returns false if the parameter is missing.
(static) size() → {Number}
This method is used to get the number of values in this priority queue.
Example
var pq = new priorityQueue ();
pq.push(1);
pq.push(2);
var size = pq.size(); // size = 2
Returns:
This method returns the number of values in this priority queue.
- Type
- Number
(static) top() → {value}
This method is used to check the top value in this priority queue, but does not remove.
Example
var pq1 = new priorityQueue ();
pq1.push(1);
pq1.push(2);
var ret1 = pq1.top(); // ret = 2
var pq2 = new priorityQueue ("greater");
pq2.push(1);
pq2.push(2);
var ret2 = pq2.top(); // ret = 1
Throws:
This method returns null if the top value is empty.
Returns:
This method returns the top value of this priority queue, or null if this priority queue is empty.
- Type
- value