A doubly linked list.
Name | Description |
---|---|
T |
The type of an item's value. |
• new DoublyLinkedList<T
>(values?
, ...rest
)
Appends the specified items to the list.
Name |
---|
T |
Name | Type | Default value | Description |
---|---|---|---|
values |
T | T [] |
[] |
The starting items of the list. |
...rest |
T [] |
undefined |
The starting items by spreading. |
• length: number
= 0
▸ append(value
): void
Appends (pushes) a new item to the list.
Name | Type | Description |
---|---|---|
value |
T |
The value of a node. |
void
void
▸ clear(): void
Removes all items from the list.
void
void
▸ get(index
): T
Gets the value of the item at the specified index
.
Throws
IndexError
This exception is thrown if index
doesn't exist in the list.
Name | Type | Description |
---|---|---|
index |
number |
The index from the item. |
T
The value of the item.
▸ getHead(): undefined
| T
Retrieves the value of the first item in the list if it exists.
undefined
| T
The value of the item or undefined
.
▸ getTail(): undefined
| T
Retrieves the value of the last item in the list if it exists.
undefined
| T
The value of the item or undefined
.
▸ popHead(): undefined
| T
Removes the first item from the list if it exists.
undefined
| T
The value of the item or undefined
.
▸ popTail(): undefined
| T
Removes the last item from the list if it exists.
undefined
| T
The value of the item or undefined
.
▸ prepend(value
): void
Prepends (unshifts) a new item to the list.
Name | Type | Description |
---|---|---|
value |
T |
The value of a node. |
void
void
▸ pushAt(value
, index
): void
Inserts an item at the place of index
. The item will
end up below the item that was currently there.
Throws
IndexError
This exception is thrown if index
doesn't exist in the list.
Name | Type | Description |
---|---|---|
value |
T |
The value of the item. |
index |
number |
The index where the node will end up. |
void
void
▸ remove(index
): T
Removes the item at the place of index
.
Throws
IndexError
This exception is thrown if index
doesn't exist in the list.
Name | Type | Description |
---|---|---|
index |
number |
The index of the node. |
T
void
▸ toArray(): T
[]
Retrieves an array of all the values in the list.
T
[]
An array of all the values in the list.