priorityQueue

priorityQueue

Priority Queue(우선순위 큐)에 저장되어 있는 각 요소들은 우선순위를 가지고 있으며, 컨테이너에 저장된 요소들 중 우선순위가 높은 요소부터 순차적으로 출력된다.

Constructor

new priorityQueue(value)

Author:
  • ljsoo0925@gmail.com
Example
var pq = new priorityQueue ();
var pq = new priorityQueue (“less”);
var pq = new priorityQueue (“greater”);
Parameters:
Name Type Description
value String ORDER BY
Properties
Name Type Attributes Default Description
less String <optional>
default desc(내림차순)
greater String asc(오름차순)

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