Question DSA-TREE-0009
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 post(n):
return [] if not n else post(n.l) + post(n.r) + [n.v]
print(*post(root))
- A.
1 2 4 5 3
- B.
4 5 2 3 1
- C.
Sign up free to see the answer and a step-by-step explanation.