""" ------------------------------------------------------- [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))
Assignment 9, Task 4 - node_counts, __contains__, parent (iterative), parent_r (recursive) ------------------------------------------------------------------------ Author: Nicolas Mills ID: 180856100 Email: [email protected] __updated__ = 2019-03-28 ------------------------------------------------------------------------ """ from BST_linked import BST print('Testing BST#node_counts') print('\n\nEmpty BST') bst = BST() zero, one, two = bst.node_counts() print("Nodes w/ ZERO children: {}\tExpected: {}".format(zero, 0)) print("Nodes w/ ONE children: {}\t\tExpected: {}".format(one, 0)) print("Nodes w/ TWO children: {}\t\tExpected: {}".format(two, 0)) print('\n\nNon-empty BST with only two nodes') bst = BST() for val in [2,4]: bst.insert(val) zero, one, two = bst.node_counts() print("Nodes w/ ZERO children: {}\tExpected: {}".format(zero, 1)) print("Nodes w/ ONE child: {}\t\tExpected: {}".format(one, 1)) print("Nodes w/ TWO children: {}\t\tExpected: {}".format(two, 0)) print('\n\nNon-empty BALANCED BST with 3 nodes') bst = BST()