如下是二叉树的建立和输出,结果不对,帮忙看下,谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/10 10:22:07
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#define NULL 0
typedef struct bitnode
{
float data;
bitnode *lchild,*rchild;
}bitnode,*bitree;

bitree creatbitree(bitree T,float n,float i,float s,float u)
{ //s表示根节点值,u表示子节点的值和根节点的值的关系,n表示需要输出多少行。

if(i>n){T=NULL;return 0;}
else
{ T=(bitree )malloc (sizeof(bitnode ));
T->data=s;
T->lchild=creatbitree(T,n,i+1,s*u,u);
T->rchild=creatbitree(T,n,i+1,s/u,u);
return 0;}
}
void output(bitree T){
if(T!=NULL){
cout<<T->data<<endl;
output(T->lchild);
output(T->rchild);
}else ;
}
int main(){bitree Y=NULL;
float n,i=1;
float s,u;
cout<<"s=";
cin>>s;
cout<<"n=";
cin>>n;

bitree creatbitree(bitree T,float n,float i,float s,float u)
函数的参数有问题, 第一个参数:
bitree T 应该 :
bitree & T,或者 bitree*T;
其它地方相应修改

creatbitree函数里有问题
因该这样吧:creatbitree(T->lchild,n,i+1,s*u,u);