注册 登录
编程论坛 数据结构与算法

求二叉树中的叶子结点个数

WL2311296974 发布于 2017-06-06 23:08, 3146 次点击
运行结果总是为  0  怎么回事!!!



#include "stdio.h"
#include "stdlib.h"
#include "malloc.h"
typedef char ElemType;
typedef struct BTNode
{
     ElemType data;
     struct BTNode *lchild,*rchild;
}BTNode,*BTree;
int Leaf(BTree p)
{
    int count=0;
    if(p==NULL)
    {
        return count;
    }
    else
    if(p!=NULL)
    {
        if(p->lchild==NULL&&p->rchild==NULL)
             count++;
        Leaf(p->lchild);
        Leaf(p->rchild);
    }   
}
int main()
{
     int count;
     count=Leaf(T);
     printf("该二叉树中的叶子结点的个数为:%d\n",count);
}
3 回复
#2
九转星河2017-06-07 19:11
怎么没有发现输入信息?~
#3
yangfrancis2017-06-08 21:21
把局部变量的count注释掉
#4
yangfrancis2017-06-08 21:22
T是未定义变量吧?
1