首页 > 其他 > 详细

二叉树各节点的实现

时间:2016-01-26 12:09:47      阅读:123      评论:0      收藏:0      [点我收藏+]
//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;
}

 

二叉树各节点的实现

原文:http://www.cnblogs.com/CClarence/p/5159567.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!