0

Help pls

class Node: def __init__(self, data): self.data = data self.left = None self.right = None def print_tree(root, space=0, t=0): COUNT = 3 if root is None: return space += COUNT print_tree(root.right, space, 1) for x in range(COUNT, space): print(" ",end = "") if t == 1 : # Right node print("/ ", root.data) elif t == 2 : # Left node print("\ ", root.data) else: # Root node print(root.data) #Process left child print_tree(root.left, space, 2) root = Node(1) root.left = Node(2) root.right = Node(3) root.left.left = Node(4) root.left.right = Node(5) root.right.left = Node(6) root.right.right = Node(7) print_tree(root) In this code there are two recursions, i am not understanding those parts.

22nd Jul 2020, 7:20 PM
Shafayet Arish
Shafayet Arish - avatar
2 odpowiedzi
+ 1
if you ask your grandma /pA for their desendents, they will say: our children and their desendents... right? So make a tree of your family Grandma/pa is a root but also their children. And thise are also a node relative to their parents .
22nd Jul 2020, 7:31 PM
Oma Falk
Oma Falk - avatar
0
What is the functionality of root.right and root.left?
22nd Jul 2020, 7:37 PM
Shafayet Arish
Shafayet Arish - avatar