( Latest Revision: 11/23/2004 )

Working With Trees: Extending the Binary Search Tree Class


PRELIMINARIES:

Before starting this assignment you need to be familiar with queues and binary search trees. You also need to be familiar with the directions and examples here: http://www.cs.csustan.edu/~john/Classes/General_Info/progAsgRules/


THE ASSIGNMENT:


IMPLEMENTATIONS:

Keep in mind that it is your responsibility to write the driver and to fill in certain function bodies in the BST2.cpp file. On the other hand, you must not make any "unauthorized" changes to BST2.cpp. Also, you must not change any of the other *.h or *.cpp files I am giving you in the assignment directory.

Make recTreeCount, recTreeHeight, and recRevOrderPrint recursive functions. Implement TreeCount simply by making a single call to its recursive counterpart recTreeCount. Implement TreeHeight and RevOrderPrint similarly with calls to their recursive counterparts recTreeHeight and recRevOrderPrint. In class we will discuss details of the algorithms to be used by recTreeCount, recTreeHeight, and recRevOrderPrint.

For LevOrderPrint, I recommend a solution that employs a queue as an auxiliary data structure. I have given you copies of the files QueueP.h and QueueP.cpp. These files implement a queue data structure that you can use in your LevOrderPrint function. All the include statements necessary are already in place. You will be able declare and use a local variable of type queueClass within your LevOrderPrint function. Also you will be able to declare and use local variables of type treeRef. The treeRef data type is the data type that we place into the queue. A treeRef is a struct with two fields: a pointer that points to a node N in a binary search tree T, and an integer that represents the level of N within T. In class we will discuss more details concerning these data types and also we will discuss the algorithm to be used by the LevOrderPrint function.


COMPILING

The program you are writing will consist of several files. If your driver is named driver.cpp then the program will consist of all these files: driver.cpp, BST2.h, BST2.cpp, Data.h, Data.cpp, QueueP.h, and QueueP.cpp. To compile the program you could use the command:

g++ driver.cpp BST2.cpp Data.cpp QueueP.cpp
alternatively if you are working within a directory where the only files with the .cpp extension are the ones mentioned above then the following enormously simpler command will work:

g++ *.cpp
This is one reason why it is a good idea to work on each new program in a new directory.

Also, if you wish you can use this Makefile. You put a copy of the Makefile in the same directory with the rest of the program, and type make on the command line when you want to compile. (The leading whitespace you see in some of the lines of the Makefile is supposed to be a single tab. If you create the Makefile in your directory by "copying and pasting" then the tabs may get converted to a series of blanks in the process. Check and replace the tabs in the Makefile if they are not there. The Makefile won't work if you have spaces where the tabs are supposed to be.) If you use the Makefile, your compiles will tend to go a lot faster because only the files you have changed are compiled (plus the files that include files you changed). If you use the Makefile you will also see files in your directory with names having the form *.o. These are the individual object files for each of your *.cpp files. The compiler links them together into a single executable image called "driver" (instead of a.out). Just leave the object files alone. They need to be there.


WHAT TO TURN IN:

You will turn in two "phases" of this assignment:
  1. You will turn in the driver on the first due date
  2. On the second due date you will turn in a final version of the program.
For each phase of the assignment, you will turn in a printer output (hardcopy) and you will send me an e-mail message. Please follow these rules: Here is a list of the things you have to turn in: Note that there are no spaces in the subject lines given. It is important that you do not insert any spaces. My e-mail address is: john@ishi.csustan.edu.


DUE DATES:

For the due dates, see the class schedule.