Homework 10

This is part 1 of your final project. Part 2 will be handed in next week. This "homework" will not be graded as a separate homework, but rather as part of your final project (worth 20% of your final grade).

You should strive to finish it, as usually, by the Wednesday night deadline. Submit whatever you have done by the deadline in the directory Hw10. I accept, without penalty, programs with a fundamentally correct design but which perhaps are not fully debugged. However, if you have not started working on this assignement, have not submitted anything or have submitted a file that has nothing to do with the assignment, your final grade on the project will be affected.

Then we will extend it to one called BinSearchTree for binary search trees.

The data structure should be implemented as described in class on Thursday. The struct definition is:

struct BTNode{

int data;

BTNode * left;

BTNode * right;

}

The class variables (private) are:

- root
- current

The class should contain the following functions:

**Constructor**: creates an empty tree**Destructor**: deletes all the nodes of the tree, deallocating the space**Insert**functions:**InsertRoot**: inserts a new node to be the root (with no children)**InsertLeft**: inserts a new node as the left child of the current node**InsertRight**: inserts a new node as the right child of the current node

**Navigation**functions:**MoveToRoot**: moves current to root**MoveLeft**: moves current to left**MoveRight**: moves current to right

**Testing**functions:**EmptyTree**: tests if the tree (starting at root) is empty**EmptyLeft**: tests if the left subtree of the current node is empty**EmptyRight**: tests if the right subtree of the current node is empty

**Delete**functions**DeleteRoot**: deletes the whole tree, starting from root, and deallocates the space**DeleteLeft**: deletes the left subtree of the current node**DeleteRight**: deletes the right subtree of the current node

**Print**functions**Print**: prints the whole tree, starting from root**PrintCurrent**: prints the subtree rooted at the current node

**Traverse**functions (to be explained in class on Tuesday)**Infix****Prefix****Postfix**

- Binary Search Tree class
- Trees (general)

The Binary Search Tree class should also contain a function to create a binary search tree starting from an array, to search for a value in the tree and to sort.

You should come up with the best solution you can for this implementation. Then you should discuss your solution with me in next Tuesday's lab to check that it is sound, before embarking (next week) on the implementation of the final step of the project (which will be handed in on Thursday).

The second part of the project will be described in more detail next week. The final program should be self contained, with a menu-driven test driver which asks the user for options and a typescript with a comprehensive set of test cases.

There will be several levels of complexity for the final project, ranging from a minimum version (needed to get a passing grade on the project) to more elaborate versions, culminating to the "exceptional" version, for those aiming at the top grade. To give you a sense of the direction, the highest version will imply working with templates for defining a general Tree class template.

I will NOT give detailed instructions for you on what to implement, what files to submit, or how to test the final project. Rather, I assume that now, at the end of the semester, you know all the software engineering principles I have taught you throughout the semester, and that you will apply them. The final project will be graded accordingly.

Ileana Streinu