第一种方法使用全局变量
int count;
int CountLeaf_Q(BiTree T)
{
if(T==NULL) return 0;
else if(T->lchild==NULL&&T->rchild==NULL) count++;
CountLeaf_Q(T->lchild);
CountLeaf_Q(T->rchild);
return count;
}
第二种方法局部变量
但是具体返回的细节不懂
int CountLeaf_J(BiTree T)
{
if(T==NULL) return 0;
else if(T->lchild==NULL&&T->rchild==NULL) return 1;
return CountLeaf_J(T->lchild)+CountLeaf_J(T->rchild);
}