title: Help with tree recursion
body: <p>I have a Person class, and I want to create a tree. Here is the contsructor for the Person class. </p>
  
  <pre><code>public Person(String name, int age, char gender, Person c1, Person c2)
  </code></pre>
  
  <p>c1 is the child on the left, and c2 is the child on the right. And so say I create three Persons like so:</p>
  
  <pre><code>Person c = new Person("Carl", 50, 'M', null, f);
  
  Person b = new Person("Barbara", 52, 'F', d, e);
  
  Person a = new Person("Adam", 75, 'M', b, c);
  </code></pre>
  
  <p>So here you say Adam is the root node, and Adam's left child is b, which is Barbara and his right c which is Carl, and so on.</p>
  
  <p>So what I want to do is write a count method, that counts the number of children including <code>this</code>. So a.count() would return 6 (if Person f doesnt have any children). </p>
  
  <p>And so here's the code I have:</p>
  
  <pre><code>public int count() // total person count including this object
  {
      if(child1==null)
          return 0; //I tried return 1 for this too didnt work
      if (child2==null)
          return 0; //also tried 1 for this
      return 1+this.child1.count() +1+this.child2.count();
  }
  </code></pre>
  
  <p>I ran this on paper several times, and it should come up with the correct result, but it's off by a few for some reason when I actually run it.</p>