BinaryNode should be a nested class within BinarySearchTree (BST), for
the purpose of information hiding. (That is, no user of our BST class should need to know about BinaryNodes.)
Note that this may require a few changes in your code:
- If you have a NULL_NODE, you'll need to make it non-static. This is less
efficient, but information hiding is worth it.
- You may need to move the NULL_NODE to the BST class. Just make it
private if you do. (And keep it final, though non-static.)
- What I ended up with was:
private
final BinaryNode
NULL_NODE =
new BinaryNode();
This required me to write a second constructor that took no parameters.
- If you have already started to add type parameters to your code, you may
need to undo a few things. Primarily, since BinaryNode inherits the type parameter, it doesn't need its own. So just use BinaryNode, not BinaryNode<T>.
(If you included the T, the inner T type would shadow the other and the
compiler doesn't allow that.) BinaryNode parameters and methods will still
be of type T.