因转码可能存在排版等问题,敬请谅解!以下文字仅供您参考:
/* 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(); }
声明:本网内容收集自互联网,旨在传播知识仅供参考,不代表本网赞同其观点,文字及图片版权归原网站所有。