Newtree函数我个人认为是没返回结果的问题,但想了想又觉得不对,反正New tree函数出不来结果,这怎么办?
#include "BTree.cpp"
int NewTree(BTNode *bt,BTNode*&t )
{
if(bt!=NULL)
{ t=(BTNode *)malloc(sizeof(BTNode));
bt->data=t->data;
if(bt->lchild!=NULL)
NewTree(bt->lchild,t->rchild);
else if(bt->rchild!=NULL)
NewTree(bt->rchild,t->lchild);
}
else t=NULL;
}
void display(BTNode*bt,BTNode *&t)
{ NewTree(bt,t);
if(t=NULL)
printf("bt树为空树");
else
{printf("新二叉树为:");
DispBTree(t);}
}
int main()
{ BTNode *bt,*t,*bt1;
CreateBTree(bt,"A(B(D,E(G,H)),C(,F(I)))");
printf("bt:");
DispBTree(bt);
printf("good");
printf("\n");
display(bt,t);
printf("good2");
DestroyBTree(bt);
CreateBTree(bt1," ");
display(bt1,t);
printf("good3");
DestroyBTree(bt1);
DestroyBTree(t);
}