Reimplement the addNode
method of the Node
class in BinarySearchTree
as a static method of the BinarySearchTree
class:
private static Node addNode(Node parent, Node newNode)
If parent
is null, return newNode
. Otherwise, recursively add newNode
to parent
and return parent
.
Your implementation should replace the three null checks in the add
and original addNode
methods with just one null check.
Draft: Insert a single node into an empty tree