abcdehhhW 2022-10-15 10:23 采纳率: 50%
浏览 10

二叉树的创建和遍历,请问为什么遍历无法输出啊



```c++
#include<iostream>
using namespace std;
struct bitree{
    int data;
    struct bitree* leftchild;
    struct bitree* rightchild;
};
void creat(bitree *T)
{
    int data;
    cin>>data; 
    if(data==-1)
    return ;
    T=new bitree;
    T->data=data;
    cout<<"请输入"<<data<<"的左子树:";
    creat(T->leftchild);
    cout<<"请输入"<<data<<"的右子树:";
    creat(T->rightchild);
    
}
void xianxu(bitree* t)
{
    if(t==NULL)
    return;
    cout<<t->data<<" ";
    xianxu(t->leftchild);
    xianxu(t->rightchild);
}
void zhongxu(bitree* t)
{
    if(t==NULL)
    return;
    zhongxu(t->leftchild );
    cout<<t->data<<" ";
    zhongxu(t->rightchild );
}
void houxu(bitree* t)
{
    if(t==NULL)
    return;
    houxu(t->leftchild);
    houxu(t->rightchild );
    cout<<t->data<<" ";
 } 
int main()
{
    bitree *t;
    creat(t);
    xianxu(t);
    zhongxu(t);
    houxu(t);
    return 0;
 } 

```

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-10-15 11:07
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 10月15日