LinkedList Class
Singly-linked list.
Constructor
LinkedList
()
Item Index
Methods
clear
()
Resets the list, removing all nodes.
get
-
index
Retrieves a value stored in a node under the given index. If the index is out of bounds, an error will be thrown.
Parameters:
-
index
Number
Returns:
getFirst
()
LinkedListNode | Null
Returns:
getLength
()
Number
Returns:
indexOf
-
value
Returns the index of the first node holding the provided value.
Parameters:
-
value
Object
Returns:
insert
-
index
-
value
Inserts a given value under the given index, shifting following values by one. Throws an error if the index is out of bounds.
Parameters:
-
index
NumberIndex under which the value should be placed.
-
value
ObjectThe value to be inserted
merge
-
list
-
[index]
Merges the list with another. Does not copy.
Parameters:
-
list
LinkedListList to be merged.
-
[index]
Number optionalIndex under which the list being merged should be placed. If no index is provided, the list is appened at the end.
removeIf
-
condition
-
[removeAll]
Removes the first or all nodes for which the provided function returns true.
Parameters:
-
condition
FunctionFunction used to evaluate whether a node should be removed. This function should accept a node value and return Boolean.
-
[removeAll]
Boolean optionalIf this parameter is true, all nodes for which the condition function will return true will be removed. If it's false, only the first matching node will be removed.
Returns:
removeIndex
-
index
Removes the node under the index from the list. If the provided index is out of bounds or the list is empty, an error with be thrown.
Parameters:
-
index
NumberIndex of the node to be removed.
Returns:
removeValue
-
value
-
[removeAll]
Removes the first or all nodes holding the given value from the list.
Parameters:
-
value
NumberValue to be removed.
-
[removeAll]
Boolean optionalIf this parameter is true, all values matching the first parameter will be removed. If it's false, only the first match will be removed.
Returns:
reverse
()
Reverses the list.
subList
-
beginIndex
-
[count]
Creates a reduced in size copy of the list. If the beginning index is out of bounds, an error will be thrown.
Parameters:
-
beginIndex
NumberIndex from which the copy process should start.
-
[count]
Number optionalNumber of nodes to be copied into the new list. If the count is out of bounds or not set, then the created list will contain all elements from the beginning index to the end of the list being copied. This value can't be negative.