MCPcopy
hub / github.com/geekcomputers/Python / main

Function main

binary_search_trees/main.py:12–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10
11
12def main() -> None:
13 # Create a BST
14 root: Optional[Node] = None
15 root = insert(root, 50)
16 root = insert(root, 30)
17 root = insert(root, 20)
18 root = insert(root, 40)
19 root = insert(root, 70)
20 root = insert(root, 60)
21 root = insert(root, 80)
22
23 # Print the inorder traversal of the BST
24 print("Inorder traversal of the original BST:")
25 print_in_range(root, 10, 90)
26
27 # Print the root to leaf paths
28 print("Root to leaf paths:")
29 print_root_to_leaf_paths(root, [])
30
31 # Check if the tree is a BST
32 print("Is the tree a BST:", is_valid_bst(root, None, None))
33
34 # Delete nodes from the BST
35 print("Deleting 20 from the BST:")
36 if root is not None:
37 root = delete_node(root, 20)
38
39 # Print the inorder traversal of the BST
40 print("Inorder traversal of the BST after deleting 20:")
41 print_in_range(root, 10, 90)
42
43 # Check if the tree is a BST
44 print("Is the tree a BST:", is_valid_bst(root, None, None))
45
46 # Delete nodes from the BST
47 print("Deleting 30 from the BST:")
48 if root is not None:
49 root = delete_node(root, 30)
50
51 # Print the inorder traversal of the BST after deleting 30
52 print("Inorder traversal of the BST after deleting 30:")
53 print_in_range(root, 10, 90)
54
55 # Check if the tree is a BST
56 print("Is the tree a BST:", is_valid_bst(root, None, None))
57
58 # Delete nodes from the BST
59 print("Deleting 50 from the BST:")
60 if root is not None:
61 root = delete_node(root, 50)
62
63 # Print the inorder traversal of the BST after deleting 50
64 print("Inorder traversal of the BST after deleting 50:")
65 print_in_range(root, 10, 90)
66
67 # Check if the tree is a BST
68 print("Is the tree a BST:", is_valid_bst(root, None, None))
69

Callers 1

main.pyFile · 0.70

Calls 7

insertFunction · 0.90
print_in_rangeFunction · 0.90
print_root_to_leaf_pathsFunction · 0.90
is_valid_bstFunction · 0.90
delete_nodeFunction · 0.90
searchFunction · 0.90
create_mirror_bstFunction · 0.90

Tested by

no test coverage detected