只写函数,root是根节点
int LeafCount(node root)
{
int i;
if(root)
{
i = !((root->lChild ? 1:0) | (root->rChild? 1:0));
return i + LeafCount(root->lChild) + LeafCount(root->rChild);
}
return 0;
}
int LeaveCount(BiTree T)
{
int i=0;if(T->leftchild)
{i++;
i+=LeaveCount(BiTree T->leftchild);}if(T->rightchild)
{i++;
i+=LeaveCount(BiTree T->rightchild);}
return i;
}
//=====采用后序遍历求二叉树的深度、结点数及叶子数的递归算法========
int TreeDepth(BinTree T)
{
int hl,hr,max;
if(T){
hl=TreeDepth(T->lchild); //求左深度
hr=TreeDepth(T->rchild); //求右深度
max=hl>hr? hl:hr; //取左右深度的最大值
NodeNum=NodeNum+1; //求结点数
if(hl==0&&hr==0) leaf=leaf+1; //若左右深度为0,即为叶子。
return(max+1);
}
else return(0);
}