Need help on Binary Tree height
<p>This is a question from grade 12 Binary tree assignment. It wants a method for BTree class to return the height of the tree. I assume when there's one node in the tree the height is 0, not sure about that, i'll ask my teacher today.</p>

<p>But anyways, here's my code, i have no idea what's wrong with it.</p>

<pre><code>public int height(){
    if(root == null){
        return -1;
    }
    return height(root, 0, 0);
}
public int height(BNode branch, int depth, int ans){
    if(depth&gt;ans){
        ans=depth;
    }
    if(branch.getLeft()!=null){
        depth+=1;
        return height(branch.getLeft(), depth, ans);
    }
    else if(branch.getRight()!=null){
        depth+=1;
        return height(branch.getRight(), depth, ans);
    }
    return ans;
}
</code></pre>

<p>This is the testing class:</p>

<pre><code>    BTree bTree = new BTree();
    bTree.add(50);
    bTree.add(60);
    bTree.add(40);
    bTree.add(35);
    bTree.add(55);
    bTree.add(45);
    bTree.add(51);
    bTree.display();
    System.out.println(bTree.height());
</code></pre>

<p>This tree should have a height of 3, but it's returning:35
40
45
50
51
55
60
2</p>

<p>Any help would be appreciated, thanks.</p>
