You just need to use this
as a reference to the curent object.
public void add(int insert) {
addRecursive(this, insert);
}
Also in Depth() you can do as following:
public int depth() => depth(this);
private int depth(Tree tree) {
// Root being null means tree doesn't exist.
if (tree == null)
return 0;
// Get the depth of the left and right subtree
// using recursion.
int leftDepth = depth(tree.lhs);
int rightDepth = depth(tree.rhs);
// Choose the larger one and add the root to it.
if (leftDepth > rightDepth)
return (leftDepth + 1);
else
return (rightDepth + 1);
}
}
CLICK HERE to find out more related problems solutions.