title: Counting genders through tree recursion
body: <p>I have a Person class with the following constructor:</p>
  
  <pre><code>public Person(String name, int age, char gender, Person c1, Person c2)
  </code></pre>
  
  <p>where c1 is the left child and c2 is the right child. I want to write a method that counts the number of Persons that match the given gender, either M or F:</p>
  
  <pre><code>public int countGender(char gen)
  {
      int count=0;
      if (this.gender==gen){
          count++;
      }
      if (child1!=null){
          if (child1.gender==gen){
              count+=1+child1.countGender(gen);
          }
          else count+=child1.countGender(gen);
      }
      if (child2!=null){
          if (child2.gender==gen){
              count+=1+child2.countGender(gen);
          }
          else count+=child2.countGender(gen);
      }
      return count;
  }
  </code></pre>
  
  <p>I've tried just about everything. I'm having a hard time imagining what happens to count every time the function calls itself. Does it reset? Or since I'm using +=, does it save itself kind of before it resets? What else is wrong with my method? Please help me understand.</p>