Question DSA-TREE-0008
MediumWhat is the output of this code?
class Node:
def __init__(self, v, l=None, r=None):
self.v, self.l, self.r = v, l, r
root = Node(1, Node(2, Node(4), Node(5)), Node(3))
def ino(n):
return [] if not n else ino(n.l) + [n.v] + ino(n.r)
print(*ino(root))
- A.
4 2 5 1 3
- B.
4 5 2 3 1
- C.
Sign up free to see the answer and a step-by-step explanation.