Linked Lists
About
A linked list is objects that are linked. This means that each object in this list, only knows who is their next object.
The weakness of a Linked List in terms of costs, is the traverse cost to get to an element.
interface LinkedListNode<T> {
value: T;
next?: LinkedListNode<T>;
}
interface DoubledLinkedListNode<T> {
value: T;
next?: DoubledLinkedListNode<T>;
previous?: DoubledLinkedListNode<T>;
}Getting specific value or at specific position
You will have to run through the linked list, since there are no indexes, until you find the desired value.
Inserting at specific position
Desconsidering the asymptotic time to find and get to the position. Inserting a new element is just updating the next property of the existent object, and updating the next from the new object. (In Doubled Linked List, there is also the previous property, and it must update the previous element and the next element, of the inserted position)
Deleting at specific position
Deleting is the same as inserting, you only update next property from the previous object. (In Doubled Linked List, you also update the previous property from the next object)
Implementation
Last updated