(
Latest Revision: 04/19/2008
)
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:
- Write a driver for certain operations of a keyed list. Use the
sample.in
and the
sample.out
files to see what the commands are and what they do. If you wish, you may
create your driver by filling out this
driver shell.
- Implement the emptyTest, insert, and delete commands seen in
sample.in
with driver functions that use the SearchTreeIsEmpty, SearchTreeInsert, and
SearchTreeDelete operations of the bstClass. The bstClass is implemented by
the files:
BST2.h,
BST2.cpp,
Data.h,
and
Data.cpp.
The Data.* files are very small and just implement the itemClass for the
bstClass. The binary search tree apparatus -- the bstClass -- is defined by
the larger BST2.* files.)
- Implement the count, height, treePrint, and levelPrint commands seen in
sample.in
by implementing new operations for the bstClass and calling them from
appropriate functions in the driver. I have specified the new bstClass
operations you are assigned to implement by putting function prototypes and
header comments in
BST2.h
that tell you what the new operations are supposed to do. There are new
prototypes for the following new public functions: TreeCount, TreeHeight,
RevOrderPrint, and LevOrderPrint. There are also new prototypes for the
following protected new recursive "workhorse" functions: recTreeCount,
recTreeHeight, and recRevOrderPrint. You must write the code for each of
these functions by filling in the appropriate "empty function" in the file
BST2.cpp.
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 to 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:
- You will turn in the
driver
on
the first due date
- 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:
- Always send me e-mail as plain text in the main message body. Never
send me attachments.
- Always use the exact subject line I specify for each message.
(I often get hundreds of e-mail messages in a week. The subject line
allows me to find, filter and sort messages.) You will lose a
significant number of points on the assignment if you use the wrong
subject line.
- Be very careful when typing the command to send e-mail. You may use
the instructions in your
Hello World! lab excercise
for guidance. Of course, you will need to make the obvious changes to
those directions -- you have to use the correct subject line and
filename.
- Always send yourself a copy of each e-mail message you send to me, and
check to see if you receive the message intact. You are
responsible for sending e-mail correctly.
Here is a list of the things you have to turn in:
- At the start of class on the
first due date,
place the following item on the "counter" in front of me:
- a hardcopy of the source code of your driver
Make sure that all of the source content shows on the paper.
Make sure all content is plainly readable and properly formatted.
- Using the subject line:
CS2500Prog5.drv
send the following item to me by e-mail Before midnight on the first due date:
One
shell archive file
(only one) containing:
- a copy of the source code for your driver.
- your test script showing adequate testing of
the driver part of your program.
- At the start of class on the second due date,
place the following items on the "counter" in front of
me:
- a hardcopy of the source code of your driver
- a hardcopy containing the code for the new functions of BST2.cpp
that you implemented. (Do not turn in any of the other parts of
BST2.cpp -- that file is too long and we don't want to waste the
paper.)
Make sure that all of the source and script content shows on the paper.
Make sure all content is plainly readable and properly formatted.
- Using the subject line:
CS2500Prog5.f
send the following items to me by e-mail Before midnight on the second due date:
One
shell archive file
(only one) containing:
- all source files for your final level
program (all *.cpp files and *.h files)
- your test script showing adequate testing of your final level program.
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.