二叉树各节点的实现

//all these functions use type node,which is same as the BinaryNode

int countNode(Node *t)
{
    if(t==NULL)
        return 0;
    return 1+countNode(t->left)+countNode(t->right);
}

int countLeaves(Node *t)
{
    if(t==NULL)
        return 0;
    else if(t->left==NULL&&t->right==NULL)
        return 1;
    return countLeaves(t->left)+countLeaves(t->right);
}

//An altenative method is to use the result countLeaves(t)-1
int countFull(Node *t)
{
    if(t==NULL)
        return 0;
    int tIsFull=(t->left!=NULl&&t->right!=NULL)?1:0;
    return tIsFull+count(t->left)+count(t->right);
    //return countLeaves(t)-1;
}
原文地址:https://www.cnblogs.com/CClarence/p/5159567.html