Class DoubleLinkedList
Defined in: DataStructures.js.
Constructor Attributes | Constructor Name and Description |
---|---|
DoubleLinkedList(args)
Class for managing a double linked list.
|
Field Attributes | Field Name and Description |
---|---|
The first node of the list.
|
|
The last node of the list.
|
|
The length of the list.
|
Method Attributes | Method Name and Description |
---|---|
addAt(item, index)
Adds the item at the index position.
|
|
allIndexesOf(item,
callback)
Returns all the position in which the item has been found in the list.
|
|
clear()
Removes all the items stored in the list.
|
|
clone()
Clones the list into a new list.
|
|
Clones the list into a new list without cloning duplicated items.
|
|
contains(item, callback)
Checks if the list contains an item that satisfy the condition represented by the
callback function.
|
|
count(callback)
Returns the number of items that satisfy the represented by the callback function.
|
|
deleteNode(node)
Deletes the node from the list.
|
|
divide(index)
Divides the list at the index position.
|
|
execute(callback)
Executes the callback function for each item of the stack.
|
|
filter(callback)
Returns the items that satisfy the condition determined by the callback.
|
|
fromArray(array)
Builds the list from the array.
|
|
getItem(index)
Gets the item at the position index.
|
|
Returns the iterator relative to the aggregate.
|
|
Returns the length of the list.
|
|
getNode(index, node)
Gets the node at the position index relative from the node.
|
|
indexOf(item, callback)
Returns the first position of the item in the list.
|
|
isEmpty()
Checks if the list is empty.
|
|
join(list)
Adds the list at the end of this list.
|
|
lastIndexOf(item,
callback)
Returns the last position of the item in the list.
|
|
modifyAt(index, item)
Changes the item stored in the index position.
|
|
multiPopBack(times)
Removes the last times items of the list.
|
|
multiPopFront(times)
Removes the first times items of the list.
|
|
Sorts the list using web workers.
|
|
peek()
Returns the first item of the list without remove it.
|
|
popBack()
Removes the last item of the list.
|
|
popFront()
Removes the first item of the list.
|
|
pushBack(item)
Adds an item at the tail of the list.
|
|
pushFront(item)
Adds an item at the head of the list.
|
|
remove(item, callback)
Removes the item from the list.
|
|
removeAll(item, callback)
Removes all the item from the list.
|
|
removeAt(index)
Removes the item at the position index.
|
|
removeSegment(from,
to)
Removes all the items stored from the from position to the to position.
|
|
reverse()
Reverses the list.
|
|
sort(callback)
Sorts the list.
|
|
split(size)
Splits the list into lists of desired size.
|
|
toArray()
Transforms the list into an array.
|
Class Detail
DoubleLinkedList(args)
Class for managing a double linked list.
- Parameters:
- {...*} args Optional
- The items for initializing the list.
Field Detail
first
The first node of the list.
last
The last node of the list.
length
The length of the list.
Method Detail
{void}
addAt(item, index)
Adds the item at the index position.
- Parameters:
- item
- {*} The item to add.
- index
- {number} The position where to add the item. If index is negative, the item won't be added.
- Returns:
- {void}
{Array}
allIndexesOf(item, callback)
Returns all the position in which the item has been found in the list.
- Parameters:
- item
- {*} The item to search.
- callback Optional, Default: function(item){return(it===item);}
- The condition to satisfy. The callback must accept the current item to check.
- Returns:
- {Array
} The positions in which the item has been found.
{void}
clear()
Removes all the items stored in the list.
- Returns:
- {void}
{DoubleLinkedList}
clone()
Clones the list into a new list.
- Returns:
- {DoubleLinkedList} The list cloned from this list.
{DoubleLinkedList}
cloneDistinct()
Clones the list into a new list without cloning duplicated items.
- Returns:
- {DoubleLinkedList} The list cloned from this list.
{boolean}
contains(item, callback)
Checks if the list contains an item that satisfy the condition represented by the callback function.
- Parameters:
- item
- {*} The item to find.
- callback Optional, Default: function(item){return(it===item);}
- The condition to satisfy. The callback must accept the current item to check.
- Returns:
- {boolean} True if the list contains the item that satisfy the condition, false otherwise.
{number}
count(callback)
Returns the number of items that satisfy the represented by the callback function.
- Parameters:
- callback
- {function} The condition to satisfy.
- Returns:
- {number} The number of items that satisfy the condition.
{void}
deleteNode(node)
Deletes the node from the list.
- Parameters:
- node
- {DLLNode} The node to delete.
- Returns:
- {void}
{DoubleLinkedList}
divide(index)
Divides the list at the index position. The node at the index position is the first new node of the list.
- Parameters:
- index
- {number} The position where to divide the list.
- Returns:
- {DoubleLinkedList} The list formed by the nodes from the index position then. If the index is out of bound, the list will be empty.
{void}
execute(callback)
Executes the callback function for each item of the stack.
This method modifies the list so if you don't need to modify it you must return the same item of the array.
- Parameters:
- callback
- {function} The function to execute for each item. The function must accept the current item on which execute the function.
- Returns:
- {void}
{Array