title: Counting nodes in a tree in Java
body: <p>First of all, I swear this is not homework, it's a question I was asked in an interview. I think I made a mess of it (though I did realise the solution requires recursion). Here is the question:</p>
  
  <p>Implement the count() method which returns the number of nodes in a tree. If a node doesn't have either a left or right child, the relevant <code>getXXChild()</code> method will return <code>null</code></p>
  
  <pre><code>class Tree {
  
    Tree getRightChild() {
      // Assume this is already implemented
    }
  
    Tree getLeftChild() {
      // Assume this is already implemented
    }
  
    int count() {
      // Implement me
    }
  }
  </code></pre>
  
  <p>My reason for asking the question is simply curious to see the correct solution, and thereby measure how bad mine was.</p>
  
  <p>Cheers,
  Tony</p>