Class buckets.Queue
A queue is a First-In-First-Out (FIFO) data structure, the first
element added to the queue will be the first one to be removed. This
implementation uses a linked list as a container.
Defined in: <../buckets.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
Creates an empty queue.
|
Method Attributes | Method Name and Description |
---|---|
add(elem)
Inserts the specified element into the end of this queue.
|
|
clear()
Removes all of the elements from this queue.
|
|
contains(elem, equalsFunction)
Returns true if this queue contains the specified element.
|
|
dequeue()
Retrieves and removes the head of this queue.
|
|
enqueue(elem)
Inserts the specified element into the end of this queue.
|
|
forEach(callback)
Executes the provided function once for each element present in this queue in
FIFO order.
|
|
isEmpty()
Checks if this queue is empty.
|
|
peek()
Retrieves, but does not remove, the head of this queue.
|
|
size()
Returns the number of elements in this queue.
|
Method Detail
{boolean}
add(elem)
Inserts the specified element into the end of this queue.
- Parameters:
- {Object} elem
- the element to insert.
- Returns:
- {boolean} true if the element was inserted, or false if it is undefined.
clear()
Removes all of the elements from this queue.
{boolean}
contains(elem, equalsFunction)
Returns true if this queue contains the specified element.
If the elements inside this stack are not comparable with the === operator, a custom equals function should be provided to perform searches, the function must receive two arguments and return true if they are equal, false otherwise. Example:
var petsAreEqualByName = function(pet1, pet2) { return pet1.name === pet2.name; }
- Parameters:
- {Object} elem
- element to search for.
- {function(Object|Object):boolean=} equalsFunction
- optional function to check if two elements are equal.
- Returns:
- {boolean} true if this queue contains the specified element, false otherwise.
{*}
dequeue()
Retrieves and removes the head of this queue.
- Returns:
- {*} the head of this queue, or undefined if this queue is empty.
{boolean}
enqueue(elem)
Inserts the specified element into the end of this queue.
- Parameters:
- {Object} elem
- the element to insert.
- Returns:
- {boolean} true if the element was inserted, or false if it is undefined.
forEach(callback)
Executes the provided function once for each element present in this queue in
FIFO order.
- Parameters:
- {function(Object):*} callback
- function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.
{boolean}
isEmpty()
Checks if this queue is empty.
- Returns:
- {boolean} true if and only if this queue contains no items; false otherwise.
{*}
peek()
Retrieves, but does not remove, the head of this queue.
- Returns:
- {*} the head of this queue, or undefined if this queue is empty.
{number}
size()
Returns the number of elements in this queue.
- Returns:
- {number} the number of elements in this queue.