You may assume the following type definitions apply in this lab assignment.
public class TreeNode
{
private Object value;
private TreeNode left;
private TreeNode right;
public TreeNode( Object initValue, TreeNode initLeft, TreeNode initRight )
{
value = initValue; left = initLeft; right = initRight;
}
public Object getValue()
{
return value;
}
public TreeNode getLeft()
{
return left;
}
public TreeNode getRight()
{
return right;
}
public void setValue( Object theNewValue )
{
value = theNewValue;
}
public void setLeft( TreeNode theNewLeft )
{
left = theNewLeft;
}
public void setRight( TreeNode theNewRight )
{
right = theNewRight;
}
}
-
Build a main menu with the following choices.
(1) Read a file from disk, build the binary tree
(2) Print the tree in order
(3) Count the nodes in the tree
-
Implement a Binary Search Tree class (BSTree
) with the following methods:
public BSTree()
public void insert(Comparable next)
private TreeNode insertHelper( TreeNode root, Comparable next )
public void printInOrder()
private void printInorderHelper( TreeNode root )
public int countNodes()
private int countNodesHelper( TreeNode root )