예제 #1
0
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")
bst = BST()
other = BST()
print("First contents: {}".format([val for val in bst]))
print("Other contents: {}".format([val for val in other]))
identical = bst.is_identical(other)
print("Identical? {}".format(identical))
print("Expected: {}".format(True))

print("\n\nFirst BST empty, other non-empty")
bst = BST()
other = BST()
for val in [7,3,9,1,4]:
    other.insert(val)
print("First contents: {}".format([val for val in bst]))
print("Other contents: {}".format([val for val in other]))
identical = bst.is_identical(other)
print("Identical? {}".format(identical))
print("Expected: {}".format(False))

print("\n\nFirst BST non-empty, other empty")
예제 #2
0
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()
print(two_child_count)

inorder = bst1.inorder()