Beispiel #1
0
print("\n\nNon-empty tree balanced")
bst = BST()
for val in [7,11,9,15,5,6,4]:
    bst.insert(val)
print("Contents: {}".format([val for val in bst]))
balanced = bst.is_balanced()
print("Balanced? {}".format(balanced))
print("Expected: {}".format(True))

print("\n\nTesting BST#is_valid")

print("\n\nEmpty bst")
bst = BST()
print("Contents: {}".format([val for val in bst]))
valid = bst.is_valid()
print("Valid? {}".format(valid))
print("Expected: {}".format(True))

print("\n\nNon-empty bst valid")
bst = BST()
for val in [11,8,15,6,7,0,18]:
    bst.insert(val)
print("Contents: {}".format([val for val in bst]))
valid = bst.is_valid()
print("Valid? {}".format(valid))
print("Expected: {}".format(True))

print("\n\nTesting BST#is_identical")

print("\n\nEmpty bsts")
Beispiel #2
0
bst1.insert(1)
bst1.insert(5)
bst1.insert(9)
bst1.insert(2)

bst2.insert(6)
bst2.insert(4)
bst2.insert(7)
bst2.insert(2)
bst2.insert(3)
bst2.insert(1)

empty = bst1.is_empty()
print(empty)

is_valid = bst1.is_valid()
print(is_valid)

is_identical = bst1.is_identical(bst2)
print(is_identical)

mini = bst1.min()
print(mini)

leaf_count = bst1.leaf_count()
print(leaf_count)

one_child_count = bst1.one_child_count()
print(one_child_count)

two_child_count = bst1.two_child_count()