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

Function main

data_structures/binary_tree/binary_tree_traversals.py:185–206  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

183
184
185def main() -> None: # Main function for testing.
186 # Create binary tree.
187 root = make_tree()
188
189 # All Traversals of the binary are as follows:
190 print(f"In-order Traversal: {list(inorder(root))}")
191 print(f"Reverse In-order Traversal: {list(reverse_inorder(root))}")
192 print(f"Pre-order Traversal: {list(preorder(root))}")
193 print(f"Post-order Traversal: {list(postorder(root))}", "\n")
194
195 print(f"Height of Tree: {height(root)}", "\n")
196
197 print("Complete Level Order Traversal: ")
198 print(f"{list(level_order(root))} \n")
199
200 print("Level-wise order Traversal: ")
201
202 for level in range(1, height(root) + 1):
203 print(f"Level {level}:", list(get_nodes_from_left_to_right(root, level=level)))
204
205 print("\nZigZag order Traversal: ")
206 print(f"{list(zigzag(root))}")
207
208
209if __name__ == "__main__":

Callers 1

Calls 9

reverse_inorderFunction · 0.85
preorderFunction · 0.85
heightFunction · 0.85
zigzagFunction · 0.85
make_treeFunction · 0.70
inorderFunction · 0.70
postorderFunction · 0.70
level_orderFunction · 0.70

Tested by

no test coverage detected