DS with JS — Linked Lists
Linked list as the name suggests are linked. A linked list can be used for implementing file systems on the computer, browser history, or resolving hash collision.
In this blog, we will be talking about the singly linked list and doubly linked list. We will start with the singly linked list and then extend it to understand the doubly linked list.
Singly Linked List
Linked lists consist of nodes. Each node has two elements, one the value we want to store and a pointer, pointing to the next
node or null
.
The first node in a linked list is called the head
while the last node is called the tail
. All linked lists are terminated with a null
. Hence the node pointing to null
becomes the tail for the linked list.
Let us consider a normal morning routine.
const routine = ['make bed', 'brush teeth', 'lemon water'];
The linked list will look like the following.