主题:[讨论]为什么我递归创建的2叉树无法输出
struct BiTree//.......定义2叉树........
{
int data;
BiTree*lchild;
BiTree*rchild;
};
BiTree*create(BiTree*T)//.......创建2叉树.......
{
int ch;
cout<<"输入结点的值"<<endl;
cin>>ch;
if(ch==999)
{
T=NULL;
cout<<"输入结束"<<endl;
}
else {
T=new BiTree;
cout<<"继续输入,输入999结束:"<<endl;
T->data=ch;//生成根结点
cout<<T->data<<"'s left:"<<endl;
create(T->lchild);
cout<<T->data<<"'s right:"<<endl;
create(T->rchild);
}//else
return T;
}//create
void preorder(BiTree*T)......递归先序遍历........
{
if(T)
{
cout<<T->data;
preorder(T->lchild);
preorder(T->rchild);
}
}//
{
int data;
BiTree*lchild;
BiTree*rchild;
};
BiTree*create(BiTree*T)//.......创建2叉树.......
{
int ch;
cout<<"输入结点的值"<<endl;
cin>>ch;
if(ch==999)
{
T=NULL;
cout<<"输入结束"<<endl;
}
else {
T=new BiTree;
cout<<"继续输入,输入999结束:"<<endl;
T->data=ch;//生成根结点
cout<<T->data<<"'s left:"<<endl;
create(T->lchild);
cout<<T->data<<"'s right:"<<endl;
create(T->rchild);
}//else
return T;
}//create
void preorder(BiTree*T)......递归先序遍历........
{
if(T)
{
cout<<T->data;
preorder(T->lchild);
preorder(T->rchild);
}
}//