Give every node a second pointer and the chain grows a backward gear; point the tail at the head and it becomes a ring with no exit.
1 Two directions
A DNode stores prev AND next — walk forward from head or backward from the tail.
2 Deletion for free
Hold node n? n.prev.next = n.next and n.next.prev = n.prev — O(1), no hunt for the predecessor.
3 Circular rings
tail.next = head closes the loop — there is no None, so traversal needs its own stop test.
4 Round-robin
Serve curr, advance, repeat: CPU schedulers and board-game turns walk a ring forever.
5 The sentinel trick
A dummy head node that never gets deleted erases every empty-list special case.
Two-way chains
Two directions1A DNode stores prev AND next — walk forward from head or backward from the tail. Deletion for free2Hold node n? n.prev.next = n.next and n.next.prev = n.prev — O(1), no hunt for the predecessor. Circular rings3tail.next = head closes the loop — there is no None, so traversal needs its own stop test. Round-robin4Serve curr, advance, repeat: CPU schedulers and board-game turns walk a ring forever. The sentinel trick5A dummy head node that never gets deleted erases every empty-list special case. 5 building blocks make up Two-way chains
Readings 8 ↔ 21 ↔ 34 — a doubly chain takes four writes to slot 27 in, not two.
1 / 7Sorted readings 8 ↔ 21 ↔ 34, each node linked BOTH ways. Reading 27 arrives — it belongs between 21 and 34.
A circular list has no None to trip over — the lap test curr == head does the stopping.
process decision input / output start / end A doubly chain walked backward from the tail — then a circular roster served exactly one lap.
modulea = DNode(10) — three pointers per node: value, prev, next. All links start as None.
Memory
a= Node(10) prev=None next=None
Console
output appears as the program runs…
Roster 7 → 13 → 19 → 29 → 7 — curr never meets None, so the lap test takes over.
1 / 7A round-robin ring: 7 → 13 → 19 → 29 → back to 7. curr holds the current turn.
Neighbour math with prev and next — plus one last None.
Your predicted output — one line per console line
Hint: Walk the pointers carefully: y.prev is 11 and y.next is 33. Chaining .prev twice from z climbs two nodes left. x.prev was never set.
Click a term, then click its meaning to lock the pair.
8 conceptsTap a card to expand ?prev + nextdrops into place
?tail.next = headdrops into place
?O(1) deletedrops into place
?curr == headdrops into place
?sentineldrops into place
?backward walkdrops into place
?round-robindrops into place
?four writesdrops into place
01A doubly node carries prev and next — two pointers, two directions of travel.
02Deletion with a known node is O(1): the neighbours splice around it directly.
03Circular lists close the ring with tail.next = head — there is no None to bump into.
04Circular traversal stops on curr == head, not on None — or it never stops.
05Round-robin schedulers, repeat playlists and turn-taking games are rings in disguise.
06A sentinel (dummy head) erases empty-list and single-node special cases.