二叉树节点数算法C语言,二叉树计算叶子节点的算法(数据结构)C语言版

因转码可能存在排版等问题,敬请谅解!以下文字仅供您参考:

/* HELLO.C -- Hello, world */ #include "stdio.h" #include "conio.h" #include "malloc.h" /*=============二叉树的二叉链表存储表示===================*/ typedef struct BiTNode {int data; struct BiTNode *lchild,*rchild;/*左右孩子指针*/ }; typedef struct BiTNode chenchen; /*=============构建二叉树======================*/ chenchen *create() {int x; static int z=0; chenchen *p; z=z+1; printf("%3d: ",z); scanf("%3d",&x); if(x!=0) {p=(chenchen*)malloc(sizeof(chenchen)); p->data=x; p->lchild=create(); p->rchild=create();} else p=0; return p; } /*=====构建函数计算叶子节点的个数======*/ int count(chenchen *t){ static int y=0; if(t) {count(t->lchild); count(t->rchild); if(t->lchild==0&&t->rchild==0) {y++;}} return y;} /*============主函数===============*/ main() { chenchen *T ;int c; printf("Input the data:"); T=create(); if(T){c=count(T);printf("Number=%d",c);} else{printf("Empty");}printf(""); getch(); }

声明:本网内容收集自互联网,旨在传播知识仅供参考,不代表本网赞同其观点,文字及图片版权归原网站所有。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值