if root is None: print('') else: nodes = [root] while nodes: next_nodes = [] for node in nodes: print(node.val) branches = [node.left, node.right] if node.left is not None: next_nodes.append(node.left) if node.right is not None: next_nodes.append(node.right) nodes = next_nodes