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