《二叉树计算叶子节点的算法(数据结构)C语言版》由会员分享,可在线阅读,更多相关《二叉树计算叶子节点的算法(数据结构)C语言版(1页珍藏版)》请在人人文库网上搜索。
1、* HELLO.C - Hello, world */#include stdio.h#include conio.h#include malloc.h/*=二叉树的二叉链表存储表示=*/typedef struct BiTNodeint 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(。
2、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:n);T=create();if(T)c=count(T);printf(nNumber=%d,c);elseprintf(Empty);printf(n);getch(。