CSCI 151 -- Program One
AVL Trees
Dr. Melody Stapleton
You are to implement the operations of an AVL tree using C++ classes. You are to structure your main program to accept and interpret file input with the following format. Listed below are the possibilities for the different categories of commands:
A INTEGER_KEY for Add (insert) the integer to the AVL tree and do any necessary rebalancing
D INTEGER_KEY for Delete the integer from the AVL tree and do any necessary rebalancing
S INTEGER_KEY for Search the AVL tree for the integer key and for a successful search, return the pointer
to the node in the tree where the key is stored. For unsuccessful search, return a NULL
pointer
P for Preorder Traversal
I for Inorder Traversal
R for Postorder Traversal
Special criteria: The commands may come in any order. Although additions (insertions) to the tree are relatively straightforward, deletions of parent nodes that have two children may result in ambiguities. If such a parent node is deleted, it is to be replaced by the deeper (as in depth in the tree) of the inorder predecessor versus the inorder successor. If the inorder predecessor and the successor are the same depth, use the inorder predecessor.
Send your output for this program to a file. For Inserts (Additions), it is an error to insert a duplicate value into the tree, be sure to notify the user of such an attempt. Tell the user if an operation is successful, as well. Be sure to give appropriate 'error' messages back to the user of your program. For example, if asked to Delete a value from the tree that was not found in the tree, you should reply that the value was not found in the tree and therefore, not deleted. For the Search operation, if the item that is being sought is found, print out a message that says you found it and what its value is. If the item is not found, print out a message to that effect. Of course, output the results of a traversal to this file, as well.
A good strategy for developing your program: Write pseudocode for your program that includes :
Take this link for a sample input file to run your program against. Your TA will provide a final input file to run your program against. Note: Your program should be *bullet-proof*, debugged and able to run correctly against *any file*!