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:

  1. 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.
  2. 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.
  3. 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.
    BST print example
  4. 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: Save the results of the the above steps in a document and submit it together with your source code.

Notes:

Turn in: No hard copy source file turn in.

Submit: using TRACS


Last Updated: 11/9/15