Calculating longest path
<p>I have a n-ary tree which contains key values (integers) in each node. I would like to calculate the minimum depth of the tree. Here is what I have come up with so far:</p>

<pre><code>int min = 0;
private int getMinDepth(Node node, int counter, int temp){
    if(node == null){
        //if it is the first branch record min
        //otherwise compare min to this value
        //and record the minimum value
        if(counter == 0){
        temp = min;     
        }else{
        temp = Math.min(temp, min);
        min = 0;
        }
        counter++;//counter should increment by 1 when at end of branch
        return temp;
    }   
    min++;        
    getMinDepth(node.q1, counter, min);
    getMinDepth(node.q2, counter, min);
    getMinDepth(node.q3, counter, min);
    getMinDepth(node.q4, counter, min);
    return temp;
}
</code></pre>

<p>The code is called like so:</p>

<pre><code>int minDepth = getMinDepth(root, 0, 0);
</code></pre>

<p>The idea is that if the tree is traversing down the first branch (branch number is tracked by counter), then we set the temp holder to store this branch depth. From then on, compare the next branch length and if it smaller, then make temp = that length. For some reason counter is not incrementing at all and always staying at zero. Anyone know what I am doing wrong?</p>
