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

Function postorder

data_structures/binary_tree/binary_tree_traversals.py:46–56  ·  view source on GitHub ↗

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

(root: Node | None)

Source from the content-addressed store, hash-verified

44
45
46def postorder(root: Node | None) -> Generator[int]:
47 """
48 Post-order traversal visits left subtree, right subtree, root node.
49 >>> list(postorder(make_tree()))
50 [4, 5, 2, 3, 1]
51 """
52 if not root:
53 return
54 yield from postorder(root.left)
55 yield from postorder(root.right)
56 yield root.data
57
58
59def inorder(root: Node | None) -> Generator[int]:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected