Class buckets.LinkedList
A linked list is a data structure consisting of a group of nodes
which together represent a sequence.
Defined in: <../buckets.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
Creates an empty Linked List.
|
Method Attributes | Method Name and Description |
---|---|
add(item, index)
Adds an element to this list.
|
|
clear()
Removes all the elements from this list.
|
|
contains(item, equalsFunction)
Returns true if this list contains the specified element.
|
|
elementAtIndex(index)
Returns the element at the specified position in this list.
|
|
equals(other, equalsFunction)
Returns true if this list is equal to the given list.
|
|
first()
Returns the first element in this list.
|
|
forEach(callback)
Executes the provided function once per element present in this list in order.
|
|
indexOf(item, equalsFunction)
Returns the index of the first occurrence of the
specified element, or -1 if the List does not contain this element.
|
|
isEmpty()
Returns true if this list contains no elements.
|
|
last()
Returns the last element in this list.
|
|
remove(item, equalsFunction)
Removes the first occurrence of the specified element in this list.
|
|
removeElementAtIndex(index)
Removes the element at the specified position in this list.
|
|
reverse()
Reverses the order of the elements in this linked list (makes the last
element first, and the first element last).
|
|
size()
Returns the number of elements in this list.
|
|
toArray()
Returns an array containing all of the elements in this list in proper
sequence.
|
- Parameters:
- {Object} item
- Element to be added.
- {number=} index
- Optional index to add the element. If no index is specified the element is added to the end of this list.
- Returns:
- {boolean} True if the element was added or false if the index is invalid or if the element is undefined.
If the elements inside the list 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} item
- Element to search for.
- {function(Object|Object):boolean=} equalsFunction
- Optional function used to check if two elements are equal.
- Returns:
- {boolean} True if this list contains the specified element, false otherwise.
- Parameters:
- {number} index
- Desired index.
- Returns:
- {*} The element at the given index or undefined if the index is out of bounds.
- Parameters:
- {buckets.LinkedList} other
- The other list.
- {function(Object|Object):boolean=} equalsFunction
- Optional function to check if two elements are equal. If the elements in the lists are custom objects you should provide a function, otherwise the === operator is used to check equality between elements.
- Returns:
- {boolean} true if this list is equal to the given list.
- Returns:
- {*} The first element of the list or undefined if the list is empty.
- 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 inside the callback.
If the elements inside this list 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} item
- Element to search for.
- {function(Object|Object):boolean=} equalsFunction
- Optional function used to check if two elements are equal.
- Returns:
- {number} The index in this list of the first occurrence of the specified element, or -1 if this list does not contain the element.
- Returns:
- {boolean} true if this list contains no elements.
- Returns:
- {*} The last element in the list or undefined if the list is empty.
If the elements inside the list 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} item
- Element to be removed from this list, if present.
- equalsFunction
- Returns:
- {boolean} True if the list contained the specified element.
- Parameters:
- {number} index
- Given index.
- Returns:
- {*} Removed element or undefined if the index is out of bounds.
- Returns:
- {number} the number of elements in this list.
- Returns:
- {Array.<*>} An array containing all of the elements in this list, in proper sequence.