zipper_lists(head_1, head_2), from Structy’s Linked List I.

Given the heads of two linked lists, weave them together so the result alternates nodes from each list: list 1’s head, then list 2’s head, then list 1’s second node, and so on. If one list runs out first, the rest of the other list goes on the end.

list_1: 1 → 3 → 5
list_2: 2 → 4 → 6
result: 1 → 2 → 3 → 4 → 5 → 6

No new nodes are made. Three pointers rewrite each node’s .next in place: tail is the end of the result so far, and current_1 and current_2 are the next unused node in each list.

structy · linked list i

zipper_lists(head_1, head_2)

list_1 = 1 → 3 → 5, list_2 = 2 → 4 → 6. One node attached per pass, alternating lists. Step through at your own pace — try predicting the next move before you click.

list_1 / current_1 list_2 / current_2 tail
1
3
5
2
4
6
tail
cur₁
cur₂