Question DSA-LL-0041
MediumWhat is the output of this code?
class N:
def __init__(self, v, nx=None):
self.v, self.nx = v, nx
h = N(1, N(2, N(3, N(4, N(5)))))
prev, cur = None, h
while cur:
cur.nx, prev, cur = prev, cur, cur.nx
out = []
while prev:
out.append(prev.v)
prev = prev.nx
print(out)
- A.
[5, 4, 3, 2, 1]
- B.
[2, 1, 4, 3, 5]
- C.
[5]
- D.
[1, 2, 3, 4, 5]
Sign up free to see the answer and a step-by-step explanation.