Esc
  • Loading…
↑ ↓ to moveEnter to openEsc to close

Doubly Linked List

Nodes linked in both directions, trading extra memory for O(1) backward traversal.

  • 1 Lesson

Dry-run engine

Insert After a Node

Every node carries two addresses, so splicing one in is a handful of pointer writes — no shifting, no traversal.

O(1) Insert
Input · Insert
25 after node 20
Output · List
Press play to run it
How it works

Wire the new node first (fresh.prev, fresh.next), then its neighbours (node.next.prev, node.next), so no address is overwritten before it has been copied.

heap_nodes[5] · prev ⇄ next

  • node0x3c40 (20)
  • fresh0x6d30 (25)
  • Pointer write—
  • Writes0 / 4

Each node stores two addresses, prev and next. We already hold node = 20 (0x3c40) and allocate fresh = 25 at 0x6d30; both of its pointers start as null.

1 / 5

Course Contents