统计二叉树非叶子结点数目(数据结构考试题)

论坛 期权论坛 期权     
Emotiona丨day   2018-4-26 14:04   6591   3
分享到 :
0 人收藏

3 个回复

倒序浏览
2#
1156860019  4级常客 | 2018-4-30 01:53:22
void PreOrder(BiTree root,int *count)
{ if(root!=NULL)
       {    if(root->LChild!=NULL || root->RChild!=NULL)
               *(count)++;
             PreOrder(root->LChild,count);
             PreOrder(root->RChild,count);
}
}
3#
真真芸  1级新秀 | 2018-4-30 01:53:23
非递归算法

void sortnotleaf(bitree tree)
{
bitree stack[30];
int top=-1,count=0;
    while(tree||top>-1)
    {
while(tree)
{
if(tree->lchild||tree->rchild)
     count++;
            stack[++top]=tree;
            tree=tree->lchild;
}
        if(top>-1)
{
            tree=stack[top--]->rchild;
}
   }
printf("The number of notleaf is %d\n",count);
}
4#
center_1980  1级新秀 | 2018-4-30 01:53:24
具有n个节点的二叉树(n>2),那么它的叶子节点的数目m是多少呢?
当n=3时,m=2
当n=4时,m=2
当n=5时,m=2
当n=6时,m=2,3
谁可以证明下,是否可以计算出来呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:
帖子:
精华:
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP