(Latest Revision: 05/08/2002)
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:
- Modify the driver you wrote for the list-of-strings class so that instead
it drives a set of commands for a "keyed list." Use the
sample.in
and the
sample.out
files to see what the modified commands are and what they do.
- 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 your responsibility is 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 should 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.
WHAT TO TURN IN:
You will turn in two sets of hardcopies and you will send two
e-mail messages.
With regard to the e-mail please follow these rules:
- Always send me e-mail as plain text in the main message body. Never send
me attachments.
- I will tell you what subject line to use with each message, and I need
you to use exactly the subject lines I give you. (I get hundreds
of e-mail messages at a time and your subject line allows me to sort
messages.)
Here is a list of the things you have to turn in:
- On the morning of the first due date , turn
in a hardcopy of your completed driver code.
- Send me an e-mail copy of your completed driver code before
midnight on the first due date. Send it by
e-mail with the subject line: CS2500,prog5.drv.
- On the morning of the second due date , turn in a hardcopy
of your completed driver code, and a hard copy 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.
- Send the following items to me by e-mail before midnight on
the second due date:
- A final version of all your program source code, and
- a script showing your test runs.
In your e-mail send me all header and source files (all *.h
files and *.cpp files) that are required to compile the program into an
executable image -- everything I need to compile the program. Combine
all the source files and the script into one
shell archive file
and e-mail me the archive file with the subject line:
CS2500,prog5.fin.
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.