The irrigation channel from plot to plot in the garden: every .next the classic code reads and writes is heard and counted. How many gates does an insert…
Why it matters
Linked lists sit behind queues, undo history, LRU caches and structures inside engines. Their strength is the opposite of an array’s: insert and delete are O(1) once the place is known, but index access is O(n). Their two classic bugs, the lost head and the reversal that cuts off the rest, are very easy to make.
The key idea
Only pointers change, never places
Common mistakes
You need the N-th element, but there is no way to jump there A linked list has no indexes: the N-th means N steps from head, O(n). If random access is common, use an array.
After deleting the first node, the whole list seems gone Move head first: head = head.next. If head.next is cut first, head follows that cut to null.
A program crashes or leaks memory after editing a linked list by hand in C Keep every pointer you still need before changing anything, free the nodes you let go, and never use a pointer to a node already freed (a dangling pointer). In JavaScript the garbage collector cleans up.
Try it in this playground
Take an index Count how many .next reads it takes to get there.
Insert in the middle Two pointers, nothing shifts.
Delete the right way One pointer skips the node thrown away, or head moves.
Reverse to the end prev, cur, next: one turn per node.