[二叉树算法]同时统计叶子节点数和非叶子节点数(递归)
//同时统计叶子节点数和非叶子节点数 10 void Count(BTNode *t,int &num1,int &num2){ if(t==null) return; else{ if(t->lchild==null && t->rchild==null){ num1++; }else{ num2++; } Count(t->lchild,num1,num2); Count(t->rchild,num1,num2); } }
//同时统计叶子节点数和非叶子节点数 10 void Count(BTNode *t,int &num1,int &num2){ if(t==null) return; else{ if(t->lchild==null && t->rchild==null){ num1++; }else{ num2++; } Count(t->lchild,num1,num2); Count(t->rchild,num1,num2); } }