previous | start | next

Recursive methods in Java classes

There is a problem with making put recursive. The subtrees, like the whole tree is referenced by the Node at its root. But Node is private in the BSTSet as usual in order to keep a clean separation between the symbol table operations and the implementation.

The solution is to use two methods, one public that doesn't expose the Node type, but which calls a private helper.

The helper method can have Node as a parameter and/or return type since it is private. So it is the helper method that can be recursive.

This approach is often required for other Java classes whenever a recursive method is a natural way to implement a member method.



previous | start | next