#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct node
{
int data;
struct node*lchild,*rchild;
}tnode,*tree;
tree creat()
{
int x;
tree t;
scanf("%d",&x);
if(x==0)t=NULL;
else
{
t=(tnode*)malloc(sizeof(tnode));
t->data=x;
t->lchild=creat();
t->rchild=creat();
}
return t;
}
int LeafNum(tree t)
{
if(t)
{
if(!t->lchild&&!t->rchild)
return 1;
return LeafNum(t->lchild)+LeafNum(t->rchild);
}
return 0;
}
int main()
{
tree t=creat();
printf("%d\n",LeafNum(t));
}
6_42_二叉树递归求叶子节点个数
最新推荐文章于 2021-10-29 16:12:04 发布