MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / inorder

Function inorder

data_structures/binary_tree/inorder_tree_traversal_2022.py:46–57  ·  view source on GitHub ↗

>>> inorder(make_tree()) [6, 10, 14, 15, 20, 25, 60]

(node: None | BinaryTreeNode)

Source from the content-addressed store, hash-verified

44
45
46def inorder(node: None | BinaryTreeNode) -> list[int]: # if node is None,return
47 """
48 >>> inorder(make_tree())
49 [6, 10, 14, 15, 20, 25, 60]
50 """
51 if node:
52 inorder_array = inorder(node.left_child)
53 inorder_array = [*inorder_array, node.data]
54 inorder_array = inorder_array + inorder(node.right_child)
55 else:
56 inorder_array = []
57 return inorder_array
58
59
60def make_tree() -> BinaryTreeNode | None:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected