Each clue points to the next

Linked Lists as Treasure Hunts

The analogy

A treasure hunt: the first clue tells you where the second clue is, the second points to the third. Nothing is numbered and nothing is in a row — to reach clue 5 you must physically follow clues 1 through 4. But slipping a new clue in is trivial: rewrite one clue to point at it.

Visualizer

Following the clues

step 1 / 18
headnull

An empty list. No numbered slots — just clues waiting to point at each other.empty list

class Node:
    def __init__(self, value, nxt=None):
        self.value, self.next = value, nxt

def insert_after(node, value):
    node.next = Node(value, node.next)
    return node.next
# two writes. nothing shifts.
Check yourself

Inserting after a known node in a linked list costs…