c语言实现二叉树的代码讲述.doc

c语言实现二叉树的代码讲述

1,2两问的程序代码如下: #include?stdio.h? #includemalloc.h? ? typedef?struct?BiTNode? {? ? char?data;? ? struct?BiTNode?*lchild,*rchild;? ? }BiTNode,*BiTree;? ? BiTree?Create(BiTree?T)? {? ? char?ch;? ? ch=getchar();? ? if(ch==#)? ? T=NULL;? ? else? {? ? T=(BiTNode?)malloc(sizeof(BiTNode));? T-data=ch;?T-lchild=Create(T-lchild);?? T-rchild=Create(T-rchild);? ? }? ? return燭;?d ? }? ? int爊ode(BiTree燭)?(T {?i? int爏um1=0,a,b;?燭 ? if(T)? ? {? ? ? if(T!=NULL) sum1++;? ? ? a=node(T-lchild);? ? ? ? ? ? ? ? ? ? sum1+=a;? ? ? ? ? ? ? ? ? ? b=node(T-rchild);? ? ? ? ? ? ? ? ? ? sum1+=b;? ? ? }? ? return爏um1;?

文档评论(0)

1亿VIP精品文档

相关文档