Theory
A linked list is a linear data structure made up of nodes. Each node stores data and a reference to another node. Unlike arrays, linked-list elements do not need to be stored in contiguous memory locations.
Example
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
const first = new Node(10);
const second = new Node(20);
first.next = second;
console.log(first.value);
console.log(first.next.value);
Expected Output
10 and 20 are displayed.
Practice
Create a linked list containing three nodes.
Interview Questions
- What is a linked list?
- What is a node?
- What is the difference between an array and linked list?
- What is a singly linked list?