Exemplo n.º 1
0
print("\n\nNon-empty bst, more than 1 leaf")
bst = BST()
for val in [3,1,5,0,2,4,6]:
    bst.insert(val)
print("Contents: {}".format([val for val in bst]))
count = bst.leaf_count()
print("Leaf count: {}".format(count))
print("Expected: {}".format(4))

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

print("\n\nEmpty BST")
bst = BST()
print("Contents: {}".format([val for val in bst]))
count = bst.one_child_count()
print("Num nodes w/ one child: {}".format(count))
print("Expected: {}".format(0))

print("\n\nNon-empty BST")
bst = BST()
for val in [7,15,4,5,3,1,18,16]:
    bst.insert(val)
print("Contents: {}".format([val for val in bst]))
count = bst.one_child_count()
print("Num nodes w/ one child: {}".format(count))
print("Expected: {}".format(3))

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

print("\n\nEmpty BST")
Exemplo n.º 2
0
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()
print(inorder)

postorder = bst1.postorder()
print(postorder)

levelorder = bst1.levelorder
print(levelorder)

remove = bst1.remove(4)