print('\n\nNon-empty BST, key IN bst') bst = BST() for val in [4,3,5,8,6]: bst.insert(val) key = 6 key_in = key in bst print("Key: {}".format(key)) print("Key in bst? {}\tExpected: {}".format(key_in, True)) print('\n\nTesting BST#parent (iterative)') print('\n\nEmpty BST') bst = BST() try: parent = bst.parent(4) except AssertionError: print("Cannot locate parent in an empty BST. Assertion thrown correctly.") print('\n\nNon-empty BST, key NOT in bst') bst = BST() for val in [5,4,2,3,7,6,8]: bst.insert(val) print("BST Contents: {}".format([val for val in bst])) key = 9 print("Key: {}".format(key)) parent = bst.parent(key) print("Parent of key: {}".format(parent)) print("Expected: {}".format(None)) print('\n\nNon-empty BST, key IN bst')
""" ------------------------------------------------------- [program description] ------------------------------------------------------- Author: Anshul Khatri ID: 193313680 Email: [email protected] Section: CP164 Winter 2020 __updated__ = "2020-04-03" ------------------------------------------------------- """ from BST_linked import BST bst = BST() num = [4, 2, 9, 3, 6] for i in num: bst.insert(i) print(bst.node_counts()) print(bst.__contains__(2)) print(bst.parent(2)) print(bst.parent_r(2))
""" ------------------------------------------------------- [program description] ------------------------------------------------------- Author: Max Dann ID: 190274440 Email: [email protected] __updated__ = "2020-03-31" ------------------------------------------------------- """ from BST_linked import BST bst = BST() bst.insert(11) bst.insert(7) bst.insert(15) bst.insert(6) bst.insert(9) bst.insert(12) bst.insert(18) bst.insert(8) yes = 7 no = 67 print(bst.node_counts()) print(yes in bst) print(no in bst) print(bst.parent(yes)) print(bst.parent_r(yes))