Esempio n. 1
0
# Test height
print("Height is: " + str(b.height))
if b.height != 2:
    print("... which is incorrect.")
    sys.exit()

# Test find return value for all ints in the BST
for i in range(len(L)):
    if (b.find(L[i])).getVal() != L[i]:
        print("Incorrect return value when finding " + str(L[i]))
        sys.exit()
print("Find Int OK.")

# Test find return value for int not in BST.
if b.find(2) != b.end():
    print("Incorrect return value when finding " + str(2))
    sys.exit()
print("Does Not Find Int OK.")

# Sort the list, to compare with inorder iteration on the BST
L.sort()

# Test BST iterator; should iterate inorder
print("traversal using iterator:")
en = b.end()
it = b.begin()
for i in range(len(L)):
    if it.getVal() != L[i]:
        print(
            str(it.getVal()) + "," + str(L[i]) +