def bst_sort(a):
        """
        -------------------------------------------------------
        Sorts an array using the Tree Sort algorithm.
        Use: Sorts.bst_sort(a)
        -------------------------------------------------------
        Parameters:
            a - an array of comparable elements (?)
        Returns:
            None
        -------------------------------------------------------
        """
        bst = BST()

        for v in a:
            bst.insert(v)

        a[:] = bst.inorder()
        return
Beispiel #2
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.two_child_count()
print("Num nodes w/ one child: {}".format(count))
print("Expected: {}".format(2))

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

print("\n\nEmpty bst")
bst = BST()
print("Contents: {}".format([val for val in bst]))
inorder = bst.inorder()
print("Inorder: {}".format(inorder))

print("\n\nNon-empty bst")
bst = BST()
for val in [7,15,4,6,5,2,3,1,18,14]:
    bst.insert(val)
print("Contents: {}".format([val for val in bst]))
inorder = bst.inorder()
print("Inorder: {}".format(inorder))

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

print("\n\nEmpty bst")
bst = BST()
print("Contents: {}".format([val for val in bst]))
Beispiel #3
0
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)
print(remove)