二叉树问题
学数据结构不久,为何我先序建立二叉树后,不能输出的呢?#include<iostream>
#include<iomanip>
using namespace std;
#define OVERFLOW 0
#define NULL 0
#define OK 1
typedef int Status;
typedef char ElemType;
typedef struct BiTree
{
ElemType data;
struct BiTree *Lchild;
struct BiTree *Rchild;
}BiTree,*Binary_Tree;
//创建一个二叉树
Status CreateBiTree(Binary_Tree &T)
{
char ch;
T=(Binary_Tree)malloc(sizeof(BiTree));
if(!T) exit(OVERFLOW);
cin>>ch;
if(ch=='@') T=NULL;
else
{
T->data=ch;
CreateBiTree(T->Lchild);
CreateBiTree(T->Rchild);
}
return OK;
}
//先遍历二叉树
Status PreShowBiTree(Binary_Tree T)
{
if(T!=NULL)
{
cout<<T->data<<setw(3);
PreShowBiTree(T->Lchild);
PreShowBiTree(T->Rchild);
}
return OK;
}
//中遍历二叉树
Status MidShowBiTree(Binary_Tree T)
{
if(T!=NULL)
{
MidShowBiTree(T->Lchild);
cout<<T->data<<setw(3);
MidShowBiTree(T->Rchild);
}
return OK;
}
//后遍历二叉树
Status BehShowBiTree(Binary_Tree T)
{
if(T!=NULL)
{
BehShowBiTree(T->Lchild);
BehShowBiTree(T->Rchild);
cout<<T->data<<setw(3);
}
return OK;
}
int main()
{
BiTree *T;
cout<<"请创建一个二叉树: "<<endl;
CreateBiTree(T);
cout<<"先序遍历: ";
PreShowBiTree(T);
cout<<endl;
cout<<"中序遍历: ";
MidShowBiTree(T);
cout<<endl;
cout<<"后序遍历: ";
BehShowBiTree(T);
cout<<endl;
return 0;
}
比如先后输入ABC@@DE@G@@F@@@ 之后按回车,怎么没有反映的呢? 麻烦帮忙解决下,不胜感激!