Class BinaryTree


For this week's lab, please implement each of these methods upon the provided BinaryTree class. You'll want to test them thoroughly. But, we don't need to see your test drivers -- we'll use our own. Good luck!


Method Summary
 BinaryTree cloneTree()
          Creates and returns an exact copy of the tree.
 int maxLeafLevel()
          Returns the level of the leaf that is farthest from the top (root) of the tree.
 void printLeavesAtLevel(int level)
          Prints to the console a list of all items organized at the specified level of the tree.
 void printPath(java.lang.Comparable keyValue)
          Prints the value at each node between and including the root and the supplied keyValue.
 

Constructor Detail

BinaryTree

public BinaryTree()
Method Detail

cloneTree

public BinaryTree cloneTree()
Creates and returns an exact copy of the tree. This copy organizes the same items and has the same structure. It does not duplicate the reference data stored within each Node. Instead, it duplicate only the tree and the nodes it contains

This method does not change any of the items or the structure of the original tree.

In the event of an error, it returns null.

Returns:
an exact copy of the tree. This copy organizes the same items and has the same structure.

maxLeafLevel

public int maxLeafLevel()
Returns the level of the leaf that is farthest from the top (root) of the tree.

The root is considered to be at level 0.

This method does not change any of the items or the structure of the original tree.

In the event of an error, it returns -1

Returns:
the level of the leaf that is farthest from the top (root) of the tree.

printPath

public void printPath(java.lang.Comparable keyValue)
Prints the value at each node between and including the root and the supplied keyValue. If keyValue is not present in the tree, nothing is printed.

This method does not change any of the items or the structure of the original tree.

It can print the nodes in any order, but cannot use a collection class.


printLeavesAtLevel

public void printLeavesAtLevel(int level)
Prints to the console a list of all items organized at the specified level of the tree. If level greater than the height of the tree or no leaves at the given level, nothing is printed. For negative heights print nothing

This method does not change any of the items or the structure of the original tree.

It can print all the leaves at the specified level