Merge Operations

Merge Two Sorted Lists, Merge K Lists, and Alternating Merge.

1
0xa1
3
0xa2
5
0xa3
2
0xb1
4
0xb2
6
0xb3
NULL
Status: Select a merge strategy.
1function mergeTwoLists(l1, l2):
2 dummy = Node(0)
3 tail = dummy
4
5 while l1 and l2:
6 if l1.val < l2.val:
7 tail.next = l1
8 l1 = l1.next
9 else:
10 tail.next = l2
11 l2 = l2.next
12 tail = tail.next
13
14 if l1: tail.next = l1
15 if l2: tail.next = l2
16
17 return dummy.next

Operations