Question DSA-LL-0013
MediumWhat is the output of this code?
class N:
def __init__(self, v, nxt=None):
self.v, self.next = v, nxt
def merge(a, b):
dummy = tail = N(0)
while a and b:
if a.v <= b.v:
tail.next, a = a, a.next
else:
tail.next, b = b, b.next
tail = tail.next
tail.next = a or b
return dummy.next
h = merge(N(1, N(3, N(5))), N(2, N(4, N(6))))
out = []
while h:
out.append(str(h.v)); h = h.next
print(" ".join(out))
- A.
6 5 4 3 2 1
- B.
2 4 6 1 3 5
- C.
1 3 5 2 4 6
- D.
1 2 3 4 5 6
Sign up free to see the answer and a step-by-step explanation.