Queue

Represents a Queue data structure

Constructor

new Queue(value)

Parameters:
NameTypeDescription
valueArray | *

The value to initialize the queue with (optional).

Properties
NameTypeDescription
firstQueueNode

The first node in the queue

lastQueueNode

The last node in the queue

sizeNumber

The number of nodes in the queue

Example
new Queue();
new Queue("Beep");
new Queue([10,20,30]);

Methods

clear()

Clears the queue

Example
const q = new Queue([10,20,30]);
q.clear(); // []

dequeue() → {Queue}

Removes and returns the first value in the queue

Returns:

The current Queue instance.

Type: 
Queue
Example
const q = new Queue([10,20,30]);
q.dequeue(); // [20,30]

enqueue(value) → {Queue}

Adds a new value to the end of the queue

Parameters:
NameTypeDescription
valueNumber

The value to add.

Returns:

The current Queue instance.

Type: 
Queue
Example
const q = new Queue([10,20]);
q.enqueue(30); // [10,20,30]

isEmpty() → {Boolean}

Checks if the queue is empty

Returns:

Whether or not the queue is empty.

Type: 
Boolean
Example
const q = new Queue([10,20,30]);
q.isEmpty(); // false

peek(returnNode) → {*|QueueNode}

Returns the first value in the queue

Parameters:
NameTypeDefaultDescription
returnNodeBooleanfalse

Whether to return the node or just the value.

Returns:

The value in the first node.

Type: 
* | QueueNode
Example
const q = new Queue([10,20,30]);
q.peek(); // 10

print() → {Queue}

Prints the values of the queue

Returns:

The current Queue instance.

Type: 
Queue
Example
const q = new Queue([10,20,30]);
q.print(); // 10,20,30

toArray() → {Array}

Returns a new array of the values in the queue

Returns:

An array of the values in the queue.

Type: 
Array
Example
const q = new Queue([10,20,30]);
q.toArray(); // [10,20,30]