(Last Revision: 11/28/98)

//////////////////////////////////////////////////
CS 2500 PROGRAMMING ASSIGNMENT #05
Binary Search Tree Abstract Data Type
EXTENDING THE BINARY SEARCH TREE CLASS
//////////////////////////////////////////////////


=================================================================
DUE DATES:

Monday, Dec 07

Turn in the written specifications for all the new operations, a copy of
your test plan, and the code for at least 1 of the 4 new operations.  The
specifications and plan may be turned in EITHER on paper OR by e-mail.
Take the code from this directory, put the new code into copies of BST2.h
and BST2.cpp, make them into a shar file, and send it to me via e-mail.
E-mail is due by midnight on the due date.  Paper copy must be turned in
at the start of class time on the due date.

Monday, Dec 14

Turn in your completed copies of BST2.h BST2.cpp, your driver.cpp file,
and a script showing the outcome of an execution.  E-mail is due by
midnight on the due date.
=================================================================

Please read chapter 10 of your textbook (Carrano) for help in
understanding this assignment.

Also, you are expected to read the class documents entitled:

programAssignmentRules, sampleProgramSubmission-level-01,
sampleProgramSubmission-level-02, sampleProgramSubmission-level-03,
howToMakeTestScript sampleTestScript-level-01 sampleTestScript-level-02,
and sampleTestScript-level-03

before beginning to do this or any programming assignment.  You will find
the documents under "CourseDocuments" in the class gopher directory.

THE ASSIGNMENT

Your assignment is to extend the Binary Search Tree ADT by adding the
following operations:

   Name          Type                     Purpose
-----------------------------------------------------------------
PrintTree       void function    Print a representation of a
                                 binary search tree to the standard
                                 output.
                                 
SimilarTrees    bool function    Determine if two binary search
                                 trees have the same shape. 

LeafCount       int function     Determine the number of leaf
                                 nodes in a binary search tree.

Ancestor        void function    Given the keyValue, print the
                                 ancestors of a node in a binary
                                 search tree.
=================================================================

In other words, you must make additions to BST2.h and BST2.cpp so that
bstClass makes the new operations available.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The function PrintTree must have output like this:

               Y This is a test string
          W This is a test string
               U This is a test string
     T This is a test string
               S This is a test string
          Q This is a test string
               O This is a test string
M This is a test string
               L This is a test string
          J This is a test string
               I This is a test string
     G This is a test string
               F This is a test string
          D This is a test string
               B This is a test string

As you can see, the tree has been printed out "sideways" with indentation
used to to put each string into the correct position relative to its
"parent".  Also, when the tree is rotated 90 degrees clockwise, the keys
can be read in order from left to right.  Let's discuss how to do this in
class.  There is a very simple way to implement this operation.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

The first part of your assignment is to write the specifications of each
operation in the following format:

--------------------------------------------------
Operation (parameter list)

Function:
Inputs:
Preconditions:
Outputs:
Postconditions:
--------------------------------------------------

Here is an example that that shows how the format looks when applied to a
void function called FindNode.  Your operations will probably all have
simpler postconditions than the ones for FindNode.

void FindNode
  (  keyType   keyValue ,
     ptrType&  nodePtr,
     ptrType&  parentPtr
   );

FUNCTION:  

Find the node that contains keyValue;

        INPUTS:  keyValue -- the key value of the tree node to be sought.

 PRECONDITIONS:  None

       OUTPUTS:  nodePtr -- a pointer for the node sought, and parentPtr
		 -- a pointer for the parent of the node sought

POSTCONDITIONS:  If the search succeeds and the node sought is not the
                 root node:

                 then nodePtr points to the node sought, and parentPtr
		 points to the parent of the node sought.

                 If the search succeeds and the node sought is the root
                 node:

                 then nodePtr points to the node sought, and parentPtr is
                 NULL.

                 If the search does not succeed and the tree is not empty:

                 then nodePtr is NULL and parentPtr points to the tree
                 node that would be the parent of the node sought, if
                 that node were in the tree.  

                 If the tree is empty:

                 then nodePtr is NULL and parentPtr is NULL.

--------------------------------------------------

Once you have specified the operations, you must implement them.  Use
recursion wherever possible.  

TESTING THE OPERATIONS

Write a test plan describing the test cases needed for each operation.
Your grade is determined in part by the completeness of your test plan.  

Create a batch test driver program driver.cpp that executes these test
cases.  The driver must write all output to standard output (the
screen).  

It's important that the output of driver.cpp be self-explanatory.  Just
from looking at the screen the user must be able to tell what the inputs
to each test are, what the test does, and what the outcome is.  For
example use "before" and "after" labels, statements, and calls to
PrintTree to accomplish this.

Your test driver is allowed to call any of the public operations that are
declared in the files BST2.h or Data.h.  Of course, your driver may also
call any of the operations that you add by making changes to bstClass.

=================================================================
DUE DATES:

Monday, Dec 07

Turn in the written specifications for all the new operations, a copy of
your test plan, and the code for at least 1 of the 4 new operations.  The
specifications and plan may be turned in EITHER on paper OR by e-mail.
Take the code from this directory, put the new code into copies of BST2.h
and BST2.cpp, make them into a shar file, and send it to me via e-mail.
E-mail is due by midnight on the due date.  Paper copy must be turned in
at the start of class time on the due date.

Monday, Dec 14

Turn in your completed copies of BST2.h BST2.cpp, your driver.cpp file,
and a script showing the outcome of an execution.  E-mail is due by
midnight on the due date.
=================================================================