Complete the implementation of the LinkedBST class, in the linkedbst.py file, discussed in this chapter. A main() has been provided in the file testbst.py to test the implementation of the LinkedBST class. You can reference this file to verify the requirements of the LinkedBST class.
"""
File: testbst.py
A tester program for binary search trees.
"""
from linkedbst import LinkedBST
def main():
tree = LinkedBST()
print("Adding D B A C F E G")
tree.add("D")
tree.add("B")
tree.add("A")
tree.add("C")
tree.add("F")
tree.add("E")
tree.add("G")
print("\nExpect True for A in tree: ", "A" in tree)
print("\nString:\n" + str(tree))
clone = LinkedBST(tree)
print("\nClone:\n" + str(clone))
print("Expect True for tree == clone: ", tree == clone)
print("\nFor loop: ", end="")
for item in tree:
print(item, end=" ")
print("\n\ninorder traversal: ", end="")
for item in tree.inorder(): print(item, end = " ")
print("\n\npreorder traversal: ", end="")
for item in tree.preorder(): print(item, end = " ")
print("\n\npostorder traversal: ", end="")
for item in tree.postorder(): print(item, end = " ")
print("\n\nlevelorder traversal: ", end="")
for item in tree.levelorder(): print(item, end = " ")
print("\n\nRemoving all items:", end = " ")
for item in "ABCDEFG":
print(tree.remove(item), end=" ")
print("\n\nExpect 0: ", len(tree))
tree = LinkedBST(range(1, 16))
print("\nAdded 1..15:\n" + str(tree))
lyst = list(range(1, 16))
import random
random.shuffle(lyst)
tree = LinkedBST(lyst)
print("\nAdded ", lyst, "\n" + str(tree))
if __name__ == "__main__":
main()
Here is the whole code link:
https://repl.it/repls/JauntyRecklessProperties#abstractcollection.py
due to restriction, I can't upload whole code here.
I got two error:
Unit Test Incomplete:
postorder() traverses nodes properly
Unit Test Complete:
postorder() does not traverse preorder
Unit Test ncomplete:
postorder() does not traverse in inorder
Unit Test Complete:
postorder() does not traverse in levelorder