How to count the number of children right in a binary tree?


How to count the number of right children in a binary tree?

This means that I only want the children marked as right.


(Left | Right)

  G   |   H
T   U |  I  J

The right children would be U,H,and J.

What would be the algorithm to find these.

int count(Tree *r){
    if(r == NULL) return 0;
    int num_l=0, num_r=0;
    if(r->left != NULL)
        num_l = count(r->left);
    if(r->right != NULL)
        num_r = count(r->right)+1;
    return num_l+num_r