DoublyLinkedList<T> extends BaseLinkedList<T, DLLNode<T>>
Represents a doubly linked list.
T
- Type of the value held by the list.
- DoublyLinkedList
constructor();
static fromArray<T>(data: T[]): DoublyLinkedList<T>;
Creates a doubly linked list from an array.
T
undefined
Parameters:
data
- Array to create the list from.
Returns: DoublyLinkedList<T>
- Doubly linked list created from the array.
at(index: number): T | undefined;
Returns the value at the specified index in the list.
Parameters:
index
- Index to retrieve the value from.
Returns: T | undefined
- Value at the index or undefined if the index is out of range.
deleteAt(index: number): T | undefined;
Deletes the node at the specified index in the list.
Parameters:
index
- Index of the node to be deleted.
Returns: T | undefined
- Value of the deleted node or undefined if the index is out of range.
insertAt(index: number, val: T): boolean;
Inserts a new node with the provided value at the specified index in the list.
Parameters:
index
- Index where the value should be inserted.val
- Value to insert at the index.
Returns: boolean
- True if the value is successfully inserted, false if the index is out of range.
nodeAt(index: number): DLLNode<T> | null;
Retrieves the node at the specified index in the list.
Parameters:
index
- Index to retrieve the node from.
Returns: DLLNode<T> | null
- Node at the index or null if the index is out of range.
pop(): T | undefined;
Removes and returns the value from the end of the list.
Returns: T | undefined
- Removed value or undefined if the list is empty.
push(val: T): DoublyLinkedList<T>;
Adds a new node with the provided value to the end of the list.
Parameters:
val
- Value to be added to the list.
Returns: DoublyLinkedList<T>
- Updated list.
reverse(): DoublyLinkedList<T>;
Reverses the order of nodes in the list.
Returns: DoublyLinkedList<T>
- The reversed list.
setAt(index: number, val: T): boolean;
Sets the value at the specified index in the list.
Parameters:
index
- Index where the value should be set.val
- Value to set at the index.
Returns: boolean
- True if the value is successfully set, false if the index is out of range.
shift(): T | undefined;
Removes and returns the value from the beginning of the list.
Returns: T | undefined
- Removed value or undefined if the list is empty.
toArray(): T[];
Converts the list into an array of its values.
Returns: T[]
- Array containing the values of the list.
unshift(val: T): DoublyLinkedList<T>;
Adds a new node with the provided value to the beginning of the list.
Parameters:
val
- Value to be added to the beginning of the list.
Returns: DoublyLinkedList<T>
- Updated list.