Queue

Queue

Queue Representation

Constructor

new Queue()

Example
const queue = new Collections.Queue();
// FOR ALL EXAMPLES BELOW. ASSUME queue IS CLEARED BEFORE EACH EXAMPLE

Methods

clear() → {undefined}

Empties the Queue
Returns:
Type
undefined

dequeue() → {*}

Removes from the queue in a first in first out manner
Example
queue.enqueue(1).enqueue(2);
queue.dequeue() // 1
Returns:
The removed data
Type
*

enqueue(data) → {Queue}

Inserts given data into queue
Example
queue.enqueue(1).enqueue(2);
Parameters:
Name Type Description
data * The data to insert into queue
Returns:
The instance that this method was called
Type
Queue

peek() → {*}

Reports but does not remove the staged element to be removed next
Example
queue.enqueue(1);
queue.peek() // returns 1 but does not remove it
Returns:
Element staged to be removed next
Type
*

size() → {number}

Reports the size of the queue
Returns:
The size of the queue
Type
number