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