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