title: Counting "sticks" (nodes with one child) in a binary search tree?
body: <p>So I am working with Binary Search Trees and one method I am having trouble with is a method called stickCt, which basically it will count the number of sticks in a tree and return the number. For it to be a stick it has to have a null and a non null child for it to be considered a stick, I have my code done and it complies but I keep getting 0 as my return value, I have no idea what is wrong I've tried moving stuff around but nothing seems to work some help would be greatly appreciated.By the way I am doing it recursively, here is the code:</p>
  
  <pre><code>// The number of nodes with exactly one non-null child
  //driver
  
  public int stickCt () {
  
      return stickCt(root);
  }
  
  private static int stickCt (IntNode T) {
      int num;
  
      //easiest case
      if (T == null) {
          num = 0;
      }
      //if the left child is null and the right child is not null
      else if (T.getLeft() == null &amp;&amp; T.getRight() != null) {
          num = stickCt(T.getRight()) + 1;
      }
      //if right child is null and left side is not null
      else if (T.getRight() == null &amp;&amp; T.getLeft() != null) {
  
          num = stickCt(T.getLeft()) + 1;
      }
      //recursive part
      else {
          num = stickCt(T.getLeft()) + stickCt(T.getRight());
  
      }
      return num;
  
  }
  </code></pre>