|
| 1 | +from tree_node import Node |
| 2 | +from insert_in_bst import insert |
| 3 | +from delete_a_node_in_bst import delete_node |
| 4 | +from search_in_bst import search |
| 5 | +from inorder_successor import inorder_successor |
| 6 | +from mirror_a_bst import create_mirror_bst |
| 7 | +from print_in_range import print_in_range |
| 8 | +from root_to_leaf_paths import print_root_to_leaf_paths |
| 9 | +from validate_bst import is_valid_bst |
| 10 | + |
| 11 | + |
| 12 | +def main(): |
| 13 | + |
| 14 | + # Create a BST |
| 15 | + root = None |
| 16 | + root = insert(root, 50) |
| 17 | + root = insert(root, 30) |
| 18 | + root = insert(root, 20) |
| 19 | + root = insert(root, 40) |
| 20 | + root = insert(root, 70) |
| 21 | + root = insert(root, 60) |
| 22 | + root = insert(root, 80) |
| 23 | + |
| 24 | + # Print the inorder traversal of the BST |
| 25 | + print("Inorder traversal of the original BST:") |
| 26 | + print_in_range(root, 10, 90) |
| 27 | + |
| 28 | + # Print the root to leaf paths |
| 29 | + print("Root to leaf paths:") |
| 30 | + print_root_to_leaf_paths(root, []) |
| 31 | + |
| 32 | + # Check if the tree is a BST |
| 33 | + print("Is the tree a BST:", is_valid_bst(root,None,None)) |
| 34 | + |
| 35 | + |
| 36 | + # Delete nodes from the BST |
| 37 | + print("Deleting 20 from the BST:") |
| 38 | + root = delete_node(root, 20) |
| 39 | + |
| 40 | + # Print the inorder traversal of the BST |
| 41 | + print("Inorder traversal of the BST after deleting 20:") |
| 42 | + print_in_range(root, 10, 90) |
| 43 | + |
| 44 | + # Check if the tree is a BST |
| 45 | + print("Is the tree a BST:", is_valid_bst(root,None,None)) |
| 46 | + |
| 47 | + |
| 48 | + # Delete nodes from the BST |
| 49 | + print("Deleting 30 from the BST:") |
| 50 | + root = delete_node(root, 30) |
| 51 | + |
| 52 | + # Print the inorder traversal of the BST after deleting 30 |
| 53 | + print("Inorder traversal of the BST after deleting 30:") |
| 54 | + print_in_range(root, 10, 90) |
| 55 | + |
| 56 | + # Check if the tree is a BST |
| 57 | + print("Is the tree a BST:", is_valid_bst(root,None,None)) |
| 58 | + |
| 59 | + # Delete nodes from the BST |
| 60 | + print("Deleting 50 from the BST:") |
| 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 | + |
| 70 | + |
| 71 | + print("Searching for 70 in the BST:", search(root, 70)) |
| 72 | + print("Searching for 100 in the BST:", search(root, 100)) |
| 73 | + print("Inorder traversal of the BST:") |
| 74 | + print_in_range(root, 10, 90) |
| 75 | + print("Creating a mirror of the BST:") |
| 76 | + mirror_root = create_mirror_bst(root) |
| 77 | + print("Inorder traversal of the mirror BST:") |
| 78 | + print_in_range(mirror_root, 10, 90) |
| 79 | + |
| 80 | +if __name__ == "__main__": |
| 81 | + main() |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
0 commit comments