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

Function inorder

data_structures/binary_tree/binary_tree_traversals.py:59–69  ·  view source on GitHub ↗

In-order traversal visits left subtree, root node, right subtree. >>> list(inorder(make_tree())) [4, 2, 5, 1, 3]

(root: Node | None)

Source from the content-addressed store, hash-verified

57
58
59def inorder(root: Node | None) -> Generator[int]:
60 """
61 In-order traversal visits left subtree, root node, right subtree.
62 >>> list(inorder(make_tree()))
63 [4, 2, 5, 1, 3]
64 """
65 if not root:
66 return
67 yield from inorder(root.left)
68 yield root.data
69 yield from inorder(root.right)
70
71
72def reverse_inorder(root: Node | None) -> Generator[int]:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected