主题:[讨论]二叉树的递归先序遍历高手帮忙改一改
#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=='$') return;
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=='$') return;
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);
}