欢迎来到CClarence的博客!!

敲代码真的是一件令人感到上瘾的事情,在我二十多年的生活中,除了打DoTa,好像没有其他的另一件事也能让我如此乐此不疲。而前端恰恰是编程与界面的最前沿,它能让快速的让你感受到自己的成果,这是一件多么令人兴奋的事啊!!我希望在两年后我毕业的时候我能真的成为一位前端码农,在五年后我能成为一位NB的前端码农!!
----------CClarence写于2015年入冬。

001

二叉树各节点的实现

//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;
}

 

posted @ 2016-01-26 10:47  CClarence  阅读(168)  评论(0编辑  收藏  举报