主题:[讨论]二叉树遍历不了了 高手进来帮忙看一看
#include<iostream.h> //输入不能终止 为什么啊 ?? 麻烦高手帮帮忙
typedef char datatype;
typedef struct Node
{
datatype data;
struct Node *lchild;
struct Node *rchild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree &bt) //创建二叉树
{
char ch;
cin>>ch;
if(ch=='$') bt=NULL;
else
{
bt=new BiTNode;
bt->data=ch;
CreateBiTree(bt->lchild);
CreateBiTree(bt->rchild);
}
}
void Visite(BiTree bt)
{
cout<<bt->data;
}
void PreOrder(BiTree bt) //先序遍历
{
if(bt==NULL) return ;
Visite(bt);
PreOrder(bt->lchild);
PreOrder(bt->rchild);
}
void main()
{
BiTree bt;
cout<<"请输入树的结点:"<<endl;
CreateBiTree(bt);
cout<<"树的先序遍历:"<<endl;
PreOrder(bt);
}
typedef char datatype;
typedef struct Node
{
datatype data;
struct Node *lchild;
struct Node *rchild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree &bt) //创建二叉树
{
char ch;
cin>>ch;
if(ch=='$') bt=NULL;
else
{
bt=new BiTNode;
bt->data=ch;
CreateBiTree(bt->lchild);
CreateBiTree(bt->rchild);
}
}
void Visite(BiTree bt)
{
cout<<bt->data;
}
void PreOrder(BiTree bt) //先序遍历
{
if(bt==NULL) return ;
Visite(bt);
PreOrder(bt->lchild);
PreOrder(bt->rchild);
}
void main()
{
BiTree bt;
cout<<"请输入树的结点:"<<endl;
CreateBiTree(bt);
cout<<"树的先序遍历:"<<endl;
PreOrder(bt);
}