《数据结构实验九》由会员分享,可在线阅读,更多相关《数据结构实验九(2页珍藏版)》请在金锄头文库上搜索。
1、#include “stdio.h“ #include “malloc.h“ #define maxsize 10 typedef struct node char data;struct node *lchild,*rchild; Bitree; Bitree *Qmaxsize; Bitree *create() char ch;int front,rear;Bitree *T,*s;T=NULL;front=1;rear=0;printf(“建立二叉树n“);ch=getchar();while(ch!=#)s=NULL;if(ch!=)s=(Bitree *)malloc(sizeof
2、(Bitree);s-data=ch;s-lchild=s-rchild=NULL;rear+;Qrear=s;if(rear=1)T=s;else if(s!=NULLelse Qfront-rchild=s;if(rear%2=1)front+;ch=getchar();return T; void visite(Bitree *T) printf(“%cn“,T-data); int countleaf(Bitree *T) if(T=NULL) return 0; else if(T-lchild=NULL) else return (countleaf(T-lchild)+countleaf(T-rchild); main() Bitree *T; T=create(); printf(“叶子结点数%dn“,countleaf(T);