|
|
@ -42,7 +42,7 @@ There are several methods to create new nodes in a linked list and all of them a |
|
|
#### addHead(value) |
|
|
#### addHead(value) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addHead(value: T): ListNode\<T\> |
|
|
addHead(value: T): ListNode<T> |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds a node with given value as the first node in list: |
|
|
Adds a node with given value as the first node in list: |
|
|
@ -66,7 +66,7 @@ list.addHead('c'); |
|
|
#### addManyHead(values) |
|
|
#### addManyHead(values) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addManyHead(values: T\[\]): ListNode\<T\>\[\] |
|
|
addManyHead(values: T[]): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds multiple nodes with given values as the first nodes in list: |
|
|
Adds multiple nodes with given values as the first nodes in list: |
|
|
@ -86,7 +86,7 @@ list.addManyHead(['x', 'y', 'z']); |
|
|
#### addTail(value) |
|
|
#### addTail(value) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addTail(value: T): ListNode\<T\> |
|
|
addTail(value: T): ListNode<T> |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds a node with given value as the last node in list: |
|
|
Adds a node with given value as the last node in list: |
|
|
@ -110,7 +110,7 @@ list.addTail('c'); |
|
|
#### addManyTail(values) |
|
|
#### addManyTail(values) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addManyTail(values: T\[\]): ListNode\<T\>\[\] |
|
|
addManyTail(values: T[]): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds multiple nodes with given values as the last nodes in list: |
|
|
Adds multiple nodes with given values as the last nodes in list: |
|
|
@ -130,7 +130,7 @@ list.addManyTail(['x', 'y', 'z']); |
|
|
#### addAfter(value, previousValue, compareFn) |
|
|
#### addAfter(value, previousValue, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addAfter(value: T, previousValue: T, compareFn = compare): ListNode\<T\> |
|
|
addAfter(value: T, previousValue: T, compareFn = compare): ListNode<T> |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds a node with given value after the first node that has the previous value: |
|
|
Adds a node with given value after the first node that has the previous value: |
|
|
@ -177,7 +177,7 @@ list.addAfter( |
|
|
#### addManyAfter(values, previousValue, compareFn) |
|
|
#### addManyAfter(values, previousValue, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addManyAfter(values: T\[\], previousValue: T, compareFn = compare): ListNode\<T\>\[\] |
|
|
addManyAfter(values: T[], previousValue: T, compareFn = compare): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds multiple nodes with given values after the first node that has the previous value: |
|
|
Adds multiple nodes with given values after the first node that has the previous value: |
|
|
@ -219,7 +219,7 @@ list.addManyAfter( |
|
|
#### addBefore(value, nextValue, compareFn) |
|
|
#### addBefore(value, nextValue, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addBefore(value: T, nextValue: T, compareFn = compare): ListNode\<T\> |
|
|
addBefore(value: T, nextValue: T, compareFn = compare): ListNode<T> |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds a node with given value before the first node that has the next value: |
|
|
Adds a node with given value before the first node that has the next value: |
|
|
@ -266,7 +266,7 @@ list.addBefore( |
|
|
#### addManyBefore(values, nextValue, compareFn) |
|
|
#### addManyBefore(values, nextValue, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addManyBefore(values: T\[\], nextValue: T, compareFn = compare): ListNode\<T\>\[\] |
|
|
addManyBefore(values: T[], nextValue: T, compareFn = compare): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds multiple nodes with given values before the first node that has the next value: |
|
|
Adds multiple nodes with given values before the first node that has the next value: |
|
|
@ -308,7 +308,7 @@ list.addManyBefore( |
|
|
#### addByIndex(value, position) |
|
|
#### addByIndex(value, position) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addByIndex(value: T, position: number): ListNode\<T\> |
|
|
addByIndex(value: T, position: number): ListNode<T> |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds a node with given value at the specified position in the list: |
|
|
Adds a node with given value at the specified position in the list: |
|
|
@ -346,7 +346,7 @@ list.addByIndex('x', -1); |
|
|
#### addManyByIndex(values, position) |
|
|
#### addManyByIndex(values, position) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addManyByIndex(values: T\[\], position: number): ListNode\<T\>\[\] |
|
|
addManyByIndex(values: T[], position: number): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds multiple nodes with given values at the specified position in the list: |
|
|
Adds multiple nodes with given values at the specified position in the list: |
|
|
@ -380,7 +380,7 @@ list.addManyByIndex(['x', 'y'], -1); |
|
|
#### add(value).head() |
|
|
#### add(value).head() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
add(value: T).head(): ListNode\<T\> |
|
|
add(value: T).head(): ListNode<T> |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds a node with given value as the first node in list: |
|
|
Adds a node with given value as the first node in list: |
|
|
@ -408,7 +408,7 @@ list.add('c').head(); |
|
|
#### add(value).tail() |
|
|
#### add(value).tail() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
add(value: T).tail(): ListNode\<T\> |
|
|
add(value: T).tail(): ListNode<T> |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds a node with given value as the last node in list: |
|
|
Adds a node with given value as the last node in list: |
|
|
@ -436,7 +436,7 @@ list.add('c').tail(); |
|
|
#### add(value).after(previousValue, compareFn) |
|
|
#### add(value).after(previousValue, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
add(value: T).after(previousValue: T, compareFn = compare): ListNode\<T\> |
|
|
add(value: T).after(previousValue: T, compareFn = compare): ListNode<T> |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds a node with given value after the first node that has the previous value: |
|
|
Adds a node with given value after the first node that has the previous value: |
|
|
@ -483,7 +483,7 @@ list |
|
|
#### add(value).before(nextValue, compareFn) |
|
|
#### add(value).before(nextValue, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
add(value: T).before(nextValue: T, compareFn = compare): ListNode\<T\> |
|
|
add(value: T).before(nextValue: T, compareFn = compare): ListNode<T> |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds a node with given value before the first node that has the next value: |
|
|
Adds a node with given value before the first node that has the next value: |
|
|
@ -530,7 +530,7 @@ list |
|
|
#### add(value).byIndex(position) |
|
|
#### add(value).byIndex(position) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
add(value: T).byIndex(position: number): ListNode\<T\> |
|
|
add(value: T).byIndex(position: number): ListNode<T> |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds a node with given value at the specified position in the list: |
|
|
Adds a node with given value at the specified position in the list: |
|
|
@ -572,7 +572,7 @@ list.add('x').byIndex(-1); |
|
|
#### addMany(values).head() |
|
|
#### addMany(values).head() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addMany(values: T\[\]).head(): ListNode\<T\>\[\] |
|
|
addMany(values: T[]).head(): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds multiple nodes with given values as the first nodes in list: |
|
|
Adds multiple nodes with given values as the first nodes in list: |
|
|
@ -596,7 +596,7 @@ list.addMany(['x', 'y', 'z']).head(); |
|
|
#### addMany(values).tail() |
|
|
#### addMany(values).tail() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addMany(values: T\[\]).tail(): ListNode\<T\>\[\] |
|
|
addMany(values: T[]).tail(): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds multiple nodes with given values as the last nodes in list: |
|
|
Adds multiple nodes with given values as the last nodes in list: |
|
|
@ -620,7 +620,7 @@ list.addMany(['x', 'y', 'z']).tail(); |
|
|
#### addMany(values).after(previousValue, compareFn) |
|
|
#### addMany(values).after(previousValue, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addMany(values: T\[\]).after(previousValue: T, compareFn = compare): ListNode\<T\>\[\] |
|
|
addMany(values: T[]).after(previousValue: T, compareFn = compare): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds multiple nodes with given values after the first node that has the previous value: |
|
|
Adds multiple nodes with given values after the first node that has the previous value: |
|
|
@ -662,7 +662,7 @@ list |
|
|
#### addMany(values).before(nextValue, compareFn) |
|
|
#### addMany(values).before(nextValue, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addMany(values: T\[\]).before(nextValue: T, compareFn = compare): ListNode\<T\>\[\] |
|
|
addMany(values: T[]).before(nextValue: T, compareFn = compare): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds multiple nodes with given values before the first node that has the next value: |
|
|
Adds multiple nodes with given values before the first node that has the next value: |
|
|
@ -704,7 +704,7 @@ list |
|
|
#### addMany(values).byIndex(position) |
|
|
#### addMany(values).byIndex(position) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
addMany(values: T\[\]).byIndex(position: number): ListNode\<T\>\[\] |
|
|
addMany(values: T[]).byIndex(position: number): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Adds multiple nodes with given values at the specified position in the list: |
|
|
Adds multiple nodes with given values at the specified position in the list: |
|
|
@ -748,7 +748,7 @@ There are a few methods to remove nodes from a linked list and all of them are s |
|
|
#### dropHead() |
|
|
#### dropHead() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropHead(): ListNode\<T\> | undefined |
|
|
dropHead(): ListNode<T> | undefined |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the first node from the list: |
|
|
Removes the first node from the list: |
|
|
@ -768,7 +768,7 @@ list.dropHead(); |
|
|
#### dropManyHead(count) |
|
|
#### dropManyHead(count) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropManyHead(count: number): ListNode\<T\>\[\] |
|
|
dropManyHead(count: number): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the first nodes from the list based on given count: |
|
|
Removes the first nodes from the list based on given count: |
|
|
@ -788,7 +788,7 @@ list.dropManyHead(2); |
|
|
#### dropTail() |
|
|
#### dropTail() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropTail(): ListNode\<T\> | undefined |
|
|
dropTail(): ListNode<T> | undefined |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the last node from the list: |
|
|
Removes the last node from the list: |
|
|
@ -808,7 +808,7 @@ list.dropTail(); |
|
|
#### dropManyTail(count) |
|
|
#### dropManyTail(count) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropManyTail(count: number): ListNode\<T\>\[\] |
|
|
dropManyTail(count: number): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the last nodes from the list based on given count: |
|
|
Removes the last nodes from the list based on given count: |
|
|
@ -828,7 +828,7 @@ list.dropManyTail(2); |
|
|
#### dropByIndex(position) |
|
|
#### dropByIndex(position) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropByIndex(position: number): ListNode\<T\> | undefined |
|
|
dropByIndex(position: number): ListNode<T> | undefined |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the node with the specified position from the list: |
|
|
Removes the node with the specified position from the list: |
|
|
@ -862,7 +862,7 @@ list.dropByIndex(-2); |
|
|
#### dropManyByIndex(count, position) |
|
|
#### dropManyByIndex(count, position) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropManyByIndex(count: number, position: number): ListNode\<T\>\[\] |
|
|
dropManyByIndex(count: number, position: number): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the nodes starting from the specified position from the list based on given count: |
|
|
Removes the nodes starting from the specified position from the list based on given count: |
|
|
@ -896,7 +896,7 @@ list.dropManyByIndex(2, -2); |
|
|
#### dropByValue(value, compareFn) |
|
|
#### dropByValue(value, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropByValue(value: T, compareFn = compare): ListNode\<T\> | undefined |
|
|
dropByValue(value: T, compareFn = compare): ListNode<T> | undefined |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the first node with given value from the list: |
|
|
Removes the first node with given value from the list: |
|
|
@ -934,7 +934,7 @@ list.dropByValue(0, (value, searchedValue) => value.x === searchedValue); |
|
|
#### dropByValueAll(value, compareFn) |
|
|
#### dropByValueAll(value, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropByValueAll(value: T, compareFn = compare): ListNode\<T\>\[\] |
|
|
dropByValueAll(value: T, compareFn = compare): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes all nodes with given value from the list: |
|
|
Removes all nodes with given value from the list: |
|
|
@ -972,7 +972,7 @@ list.dropByValue(0, (value, searchedValue) => value.x === searchedValue); |
|
|
#### drop().head() |
|
|
#### drop().head() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
drop().head(): ListNode\<T\> | undefined |
|
|
drop().head(): ListNode<T> | undefined |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the first node in list: |
|
|
Removes the first node in list: |
|
|
@ -996,7 +996,7 @@ list.drop().head(); |
|
|
#### drop().tail() |
|
|
#### drop().tail() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
drop().tail(): ListNode\<T\> | undefined |
|
|
drop().tail(): ListNode<T> | undefined |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the last node in list: |
|
|
Removes the last node in list: |
|
|
@ -1020,7 +1020,7 @@ list.drop().tail(); |
|
|
#### drop().byIndex(position) |
|
|
#### drop().byIndex(position) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
drop().byIndex(position: number): ListNode\<T\> | undefined |
|
|
drop().byIndex(position: number): ListNode<T> | undefined |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the node with the specified position from the list: |
|
|
Removes the node with the specified position from the list: |
|
|
@ -1058,7 +1058,7 @@ list.drop().byIndex(-2); |
|
|
#### drop().byValue(value, compareFn) |
|
|
#### drop().byValue(value, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
drop().byValue(value: T, compareFn = compare): ListNode\<T\> | undefined |
|
|
drop().byValue(value: T, compareFn = compare): ListNode<T> | undefined |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the first node with given value from the list: |
|
|
Removes the first node with given value from the list: |
|
|
@ -1100,7 +1100,7 @@ list |
|
|
#### drop().byValueAll(value, compareFn) |
|
|
#### drop().byValueAll(value, compareFn) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
drop().byValueAll(value: T, compareFn = compare): ListNode\<T\>\[\] |
|
|
drop().byValueAll(value: T, compareFn = compare): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes all nodes with given value from the list: |
|
|
Removes all nodes with given value from the list: |
|
|
@ -1142,7 +1142,7 @@ list |
|
|
#### dropMany(count).head() |
|
|
#### dropMany(count).head() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropMany(count: number).head(): ListNode\<T\>\[\] |
|
|
dropMany(count: number).head(): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the first nodes from the list based on given count: |
|
|
Removes the first nodes from the list based on given count: |
|
|
@ -1166,7 +1166,7 @@ list.dropMany(2).head(); |
|
|
#### dropMany(count).tail() |
|
|
#### dropMany(count).tail() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropMany(count: number).tail(): ListNode\<T\>\[\] |
|
|
dropMany(count: number).tail(): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the last nodes from the list based on given count: |
|
|
Removes the last nodes from the list based on given count: |
|
|
@ -1190,7 +1190,7 @@ list.dropMany(2).tail(); |
|
|
#### dropMany(count).byIndex(position) |
|
|
#### dropMany(count).byIndex(position) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
dropMany(count: number).byIndex(position: number): ListNode\<T\>\[\] |
|
|
dropMany(count: number).byIndex(position: number): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Removes the nodes starting from the specified position from the list based on given count: |
|
|
Removes the nodes starting from the specified position from the list based on given count: |
|
|
@ -1234,7 +1234,7 @@ There are a few methods to find specific nodes in a linked list. |
|
|
#### find(predicate) |
|
|
#### find(predicate) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
find(predicate: ListIteratorFunction\<T\>): ListNode\<T\> | undefined |
|
|
find(predicate: ListIteratorFunction<T>): ListNode<T> | undefined |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Finds the first node from the list that matches the given predicate: |
|
|
Finds the first node from the list that matches the given predicate: |
|
|
@ -1258,7 +1258,7 @@ found.next.value === "b" |
|
|
#### findIndex(predicate) |
|
|
#### findIndex(predicate) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
findIndex(predicate: ListIteratorFunction\<T\>): number |
|
|
findIndex(predicate: ListIteratorFunction<T>): number |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Finds the position of the first node from the list that matches the given predicate: |
|
|
Finds the position of the first node from the list that matches the given predicate: |
|
|
@ -1286,7 +1286,7 @@ i3 === -1 |
|
|
#### get(position) |
|
|
#### get(position) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
get(position: number): ListNode\<T\> | undefined |
|
|
get(position: number): ListNode<T> | undefined |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Finds and returns the node with specific position in the list: |
|
|
Finds and returns the node with specific position in the list: |
|
|
@ -1372,7 +1372,7 @@ There are a few ways to iterate over or display a linked list. |
|
|
#### forEach(callback) |
|
|
#### forEach(callback) |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
forEach(callback: ListIteratorFunction\<T\>): void |
|
|
forEach(callback: ListIteratorFunction<T>): void |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Runs a callback function on all nodes in a linked list from head to tail: |
|
|
Runs a callback function on all nodes in a linked list from head to tail: |
|
|
@ -1413,7 +1413,7 @@ for(const node of list) { |
|
|
#### toArray() |
|
|
#### toArray() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
toArray(): T\[\] |
|
|
toArray(): T[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Converts a linked list to an array of values: |
|
|
Converts a linked list to an array of values: |
|
|
@ -1435,7 +1435,7 @@ arr === ['a', 'b', 'c'] |
|
|
#### toNodeArray() |
|
|
#### toNodeArray() |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
toNodeArray(): T\[\] |
|
|
toNodeArray(): ListNode<T>[] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
Converts a linked list to an array of nodes: |
|
|
Converts a linked list to an array of nodes: |
|
|
|