Constructor
new Queue(value)
Parameters:
PropertiesName | Type | Description |
---|---|---|
value | Array | | The value to initialize the queue with (optional). |
Name | Type | Description |
---|---|---|
first | QueueNode | The first node in the queue |
last | QueueNode | The last node in the queue |
size | Number | The number of nodes in the queue |
- Source
Example
new Queue();
new Queue("Beep");
new Queue([10,20,30]);
Methods
clear()
Clears the queue
- Source
Example
const q = new Queue([10,20,30]);
q.clear(); // []
dequeue() → {Queue}
Removes and returns the first value in the queue
- Source
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:
Name | Type | Description |
---|---|---|
value | Number | The value to add. |
- Source
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
- Source
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:
Name | Type | Default | Description |
---|---|---|---|
returnNode | Boolean | false | Whether to return the node or just the value. |
- Source
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
- Source
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
- Source
Returns:
An array of the values in the queue.
- Type:
- Array
Example
const q = new Queue([10,20,30]);
q.toArray(); // [10,20,30]