CSC 132 Fall 2000

Lab 8

Due: end of today's lab, 9 November 2000

15 points

"Easy Sorting"

 

You will need files IntBTNode.java and InsertDriver.java from the eccentric download folder for Lab 8. IntBTNode.java is the textbook author's class for binary tree nodes that contain int data. See documentation at http://eccentric.smsu.edu/download/csc132/001/lab8/index.html. InsertDriver.java will exercise this class and in particular the method you will provide.

Your assignment is to add a new method to the IntBTNode class. Here is the specification:

Parameters:

Root - node which is root of binary tree. It is null if tree is empty

Value - integer value to be added to the tree in a new node

Returns:

Reference to the root node

Preconditions:

none.

Postconditions:

Tree will contain additional node containing value. It is placed into the tree as a new leaf node according to this constraint: At all times and for every node, every int value stored in its left subtree is less than its own int value AND every int value stored in its right subtree is greater than or equal to its own int value.

public static IntBTNode insertValue(IntBTNode root, int value)

{

// you will fill in the details of this recursive method

}

 

Here is correct output from the driver program.

values are:
-4
3
27
35
46
77
111

tree structure is:
46
    -4
        --
        27
            3
            35
    111
        77
        --

Do not modify any other methods from IntBTNode class! Submit the modified IntBTNode.java file to your eccentric upload folder.


[ Assignments | CSC 132 | Peter Sanderson | Computer Science | SMSU ]


Last reviewed: 8 November 2000

Peter Sanderson ( PeteSanderson@smsu.edu )