# Project #62830 - Java HW

Tree of Integers!

Objective:

Trees sure are neat.  Let’s take this slow and simple and make a tree of integers.  Down load this FILE, and the DRIVER and fill in the code to create a tree of integers.

The class IntBSTree is given fill in the following methods

• insert: This method returns nothing and takes in an integer value that is then placed as a new node in the tree based on the binary tree properties.  A reminder values greater than the parent go to the right subtree and values smaller go to the left subtree.  Also it may be a good idea to use a recursive method in order to place these values.
• printInorder: This method which returns nothing and has no parameters prints the in order traversal of the tree.  For in order traversal each left subtree must be visited, then the value is printed out, and finally each of the right subtrees is visited.  It is a good idea to make a recursive method to assist with this.  Also if done correctly in-order traversals print out each of the integers in ascending order.
• getDepth: The depth of a node is the number of edges from the root to that number.  This method returns nothing and takes in a parameter corresponding to the integer value of a node whose depth is returned.  If the value is not in the tree a -1 should be returned.  Again a recursive helper method may be useful to solve this.

Correct Print Out:

Int BST Tester!

Creating tree

Populating Tree with values

Testing insertion by in-order traversal

1

2

3

4

5

6

7

8

9

10

Getting depth of 6

4

Getting depth of 14

-1

Finally:

Upload the .java file to the dropbox

FILE:

```public class IntBSTree{
private class Node
{
private int data;
private Node leftChild;
private Node rightChild;
{
this.leftChild = null;
this.rightChild = null;
}
}
private Node root;

public IntBSTree()
{
root = null;
}

public void insert(int data)
{
//Code this
}

public void printInorder()
{
//Code this
}

public int getDepth(int value)
{
//Code this
}

}
```

DRIVER FILE:

```import java.util.*;
public class IntBSTreeTester {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Int BST Tester!");
System.out.println("Creating tree");
IntBSTree testTree = new IntBSTree();
System.out.println("Populating Tree with values");
int[] valArr = {4,8,10,2,1,7,3,5,9,6};
for(int i : valArr)
{
testTree.insert(i);
}
System.out.println("Testing insertion by in-order traversal");
testTree.printInorder();
System.out.println("Getting depth of 6");
System.out.println(testTree.getDepth(6));
System.out.println("Getting depth of 14");
System.out.println(testTree.getDepth(14));

}

}(I have Attached Exampel of what we did in class in Word file to this project. it should be very close to this project) ```

 Subject Computer Due By (Pacific Time) 03/18/2015 02:00 pm
TutorRating
pallavi

Chat Now!

out of 1971 reviews
amosmm

Chat Now!

out of 766 reviews
PhyzKyd

Chat Now!

out of 1164 reviews
rajdeep77

Chat Now!

out of 721 reviews
sctys

Chat Now!

out of 1600 reviews

Chat Now!

out of 770 reviews
topnotcher

Chat Now!

out of 766 reviews
XXXIAO

Chat Now!

out of 680 reviews