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.
- 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
Related courses
- ArraysContiguous, indexable memory — the foundation almost every other data structure builds on.12 lessons · 16 problems
- StringsCharacter arrays with their own set of classic patterns — two pointers, sliding window, and more.19 lessons · 19 problems
- Linked ListNodes linked one direction by pointers instead of contiguous memory.4 lessons · 12 problems
