Binary Search Trees
Due: Thursday 11/19 11:55pm
Goal
1. Understanding Binary Search Trees.
Requirements:
At the file BST.cpp you will find part of a program that handles Binary Search Trees. At the program, the function bst_insert(), which is used to insert items to the BST has been implemented. You are asked to write the following methods:
- Write the method bst_search() (with appropriate parameters), which can be used to check if an integer key exists in the tree or not. The method should return a pointer to the node that contains the key or NULL if the key does not exist in the tree.
- Write the method bst_delete() (with appropriate parameters), which can be use to delete a key from the tree, if that key exists in the tree. If the key does not exist in the tree, it should print a message and return. The method returns a pointer to the root of the tree in either case.
- Write the method print_binary_tree() (with appropriate parameters), which prints they keys of the tree as shown bellow. Each line should contain one integer. The root of the tree should be at the left and the leaves at the right. Hint: use recursion.

- Write the method free_binary_tree() (with appropriate parameters), which frees the memory occupied by the BST by deleting all the nodes of the tree, starting from the leaves and going all they way up to the root.
Run and test your program as follows:
- print the contents of the tree
- insert the integers 20, 30 and 23 in that order
- print the contents of the tree
- insert the integers 8, 1 and 26 in that order
- print the contents of the tree
- insert the integers 15, 40, 4, 28, 2 and 25 in that order
- print the contents of the tree
- search for the keys 15, 25, 35
- delete the keys 15, 1, 32 and 20 in that order
- print the contents of the tree
- free the nodes of the BST
- print the contents of the tree
- terminate the program
Save the results of the the above steps in a document and submit it together with your source code.
Notes:
- You must do this program by yourself.
- Hand in a zipped file named prog05_xxxxxx.zip where xxxxxx is your TXstate id number.
- Include the BST.cpp file.
- Include the Output.txt file.
- Be sure to follow the documentation standards for the course.
Turn in: No hard copy source file turn in.
Submit: using TRACS
Last Updated: 11/9/15