CS14 - At-Home Programming Assignment 3


The project

In this assignment, you will be implementing a binary search tree. You must use a linked implementation of a tree. Each node in the tree will be represented by a Node class and should have a left and right subtree pointer. Each node in your tree should hold a string (note: a string can be more than one word) and also contain an integer called count. Include the following functions for the tree. For each operation, I have included the function prototype that you must use so that your tree will interface with the main test file. This is by no means an exhaustive list of the functions that you will be writing. These functions must be public functions in your tree class

Note about recursion

Some of the above functions used to interface with the main test file are not conducive for recursive methodology. However, you must write the inOrder, preOrder, postOrder, search, and remove functions recursively (you will lose points if you do not do these recursively). This may require you to overload 1 or more of the functions. For instance, preOrder is called from main but is not passed any parameter (you should not be able to pass the root from main because it should be a private variable of your tree class). However, you can overload the preOrder function so that it will operate recursively. For example, your preOrder function should look like this:
and you will write the preOrder code within the recursive function that takes a node as a parameter. You may need to do something similar for the inOrder, postOrder, search, and/or remove functions so that you can write these functions recursively. Should these functions be public or private?

Provided Skeleton Code

tree.h includes a node class that you will need to create.

Extra credit for as3

I think it is very important for you to write a function to print the tree out in this manner. For 5% extra credit, write a function to print the tree out sideways (it must LOOK exactly like my sample - we will visually check instead of doing a diff test). Here is the order the items were inserted to get the output. You must use the following function prototype: void printTreeSideways ( ) and the function must be part of the tree class. The printTreeSideways function will print the tree to a file called "mytree.out." We will only test for this function if you include a readme.txt file that states that you did implement the function. If you do not follow these specifications exactly, you may not get the extra credit. You should write this function first to help you with debugging. Also, this is actually a very easy function to write if you think about it so don't pass up this easy extra credit.

Testing

We will be grading your program with a main file that looks something like this (of course we will be using a much more rigorous main to test your program). The output should match a diff test with this

For this assignment, you will need to learn how to test and debug your own code without the help of the test file we will be using. You will need to think about what cases to test and how to test them. To ensure that your code will compile with our main testing file, make sure that your code compiles with simple_main.cc. To ensure that you output will match the diff test, DO NOT print ANYTHING out in the tree/node class functions! You should still do all of the necessary error checking but DO NOT print out error messages.

Suggestions to follow while coding

What to turn in

You should have turned in what you have thus far on our program at least 6 hours before the due date (by 2pm). Then continue to work on your program and turn in more current versions as you get them working. Ideally, you should have your project done well before the due date.

You must turn in all .cc and .h files and your makefile. In addition, you must follow any guidelines and include any information that is stated on the main page about at-home programming assignments. You must also turn in a readme file stating which test cases work and which do not. Your readme file can also include any notes or comments about your code that you would like to make to the grader.

DO NOT, I repeat, DO NOT turn in any files that are not required for the final compilation of your assignment. Do not turn in your temporary .cc files or your saved/olded revisions of your .cc files. If you turn in files that aren't required for your assignment, it hinders the grading processes. You will be docked points if you turn in extraineous files.

A reminder about collaboration on home programming assignments

Please remember, at-home programming assignments are not lab assignments and you may not team-code with your lab partner or any other individual. Limited collaboration may be acceptable, but programs must represent YOUR OWN original work. Sharing code or team-coding are strictly not allowed. Copying code from ANY source (any book, current or past students, past solutions, web, etc) is strictly not allowed even with citation. Collaboration may consist of discussing the general approach to solving the problem, but should not involve communicating in code or even pseudo-code. Students may help others find bugs. Your code MUST be unique -- the odds of randomly producing similar code is very low. Computing, like surgery or driving a car or playing golf, can only be learned by doing it yourself!