It is often convenient to write the operations on trees as recursive methods. This is because the tree is itself defined recursively.
These recursive methods generaly need to have a Node as a parameter!
Consequently, these methods can't be public.
So the pattern that arises is to have one public method that doesn't require a Node parameter and to have a private recursive method that is called to do all the work.
For example, here is a pair of get methods, one public and one private:
public Value get(Key k)
{
// Call the private recursive find
// starting at the root of the tree.
return get( k, root);
}
private Value get(Key k, Node t)
{
if ( t == null ) {
return null;
}
if ( k.compareTo(t.key) < 0 ) {
return find(x, t.left);
}
else if ( k.compareTo(t.key) > 0 ) {
return find(x, t.right);
}
else {
return t.key;
}
}