Write a python program named tree.py that creates a class
called BinaryTree that supports the following API:
- BinaryTree(comparatorFct): Creates an empty binary tree.
comparatorFct should take two keys as arguments and
return a negative integer if key1 is less than key2, 0 if the
two keys are equal, and a positive integer if key1 is greater than
key2. This function will allow a user to insert any type of object
into the binary tree.
- find(key): returns true or false depending on whether the key is
in the tree.
- insert(key): inserts the key into the tree. It should do nothing
if the key is already in the tree. There is no return value for
insert.
- traverse(): returns a list of keys in the tree in sorted order.
You should use an unbalanced binary search tree to implement your class.
Your program may define additional helper methods or helper functions, and
it may also define additional classes (e.g., you may wish to declare
a TreeNode class).
I have provided a driver program named BinaryTreeDriver.py that
you can use to test your program. It takes one command line argument,
which is either "-", which will invoke a command line interpreter, or
a filename, in which case the driver will read and execute commands from
the file. The driver accepts
the following three commands:
- INSERT key: inserts the key into the tree.
- FIND key: returns true/false depending on whether the key is in the
tree.
- PRINT: prints the contents of the tree in sorted order
- QUIT: causes the interpreter to exit. It will hang if you forget
to put a QUIT at the end of a file.
This program will test your binary tree class on strings. However, you
should be sure that it works with other types of objects as well (e.g.,
numbers, a class, etc)