这个问题我想了好几天都想,不出来,不知道有没有谁可以帮帮忙呀,,非常谢谢了!
以下是我的程序,我想在函数no(BTree *bt,int i,int *y)中计算并返回该二叉处终端结点的个数,帮帮哦,谢谢!
/*用顺序存储二叉树的各种遍历算法及其实现*/
#include "stdio.h"
#include "conio.h"
typedef char *BTree;
typedef enum {OVERFLOW=-2,ERROR,FALSE,OK,TRUE} Status;
Status InitBTree(BTree *bt,char *Node){
int Length;
int i;
for(Length=0;Node[Length];Length++);/*确定二叉树的节点数*/
*bt=(BTree)malloc((Length+1)*sizeof(char));/*分配存储空间,0#单元保存长度*/
if(!(*bt)) exit(OVERFLOW);
(*bt)[0]=Length;
for(i=0;i<Length;i++)
(*bt)[i+1]=Node[i];
return OK;
}
Status no(BTree *bt,int i,int *y){/*求终端结点的个数*/
return y;
}
main()
{ int h,y,n;
char *node="ABCDEFG##H#I#JK";
BTree *bt;
InitBTree(&bt,node);
printf("\nfist view:\n");
PT(bt,1,Visit);
printf("\nInOrder:\n");
InOrder(bt,1,Visit);
printf("\nPostOrder:\n");
PostOrder(bt,1,Visit);
printf("\nBTree:\n");
g(bt,1);
/*h=Hight(bt,1);
printf("\n%d",h); */
y=num(bt,node);
printf("\ntatol num is:%d",y);
printf("\n,,,,,,,");
n=no(bt,1,1);
printf("\n%d",n);
getch();
}