用到了二叉树算法库!二叉树的递归遍历感觉没啥好说的呀;注意一下细节吧,打好基础!
#include<bits/stdc++.h>
#include"../二叉树算法库/erchashu.h"
///#include"../二叉树算法库/erchashu.cpp"
using namespace std;
void xianxu(btnode *s)
{
if(s!=NULL)
{
cout<<s->data;
xianxu(s->lchild);
xianxu(s->rchild);
}
//cout<<endl;
}
void zhongxu(btnode *s)
{
if(s!=NULL)
{
zhongxu(s->lchild);
cout<<s->data;
zhongxu(s->rchild);
}
//cout<<endl;
}
void houxu(btnode *s)
{
if(s!=NULL)
{
houxu(s->lchild);
houxu(s->rchild);
cout<<s->data;
}
//cout<<endl;
}
int main()
{
char a[100];
gets(a);
btnode *s;
creatbtnode(s,a);
///display(s);
cout<<"先序遍历:"<<endl;
xianxu(s);
cout<<endl;
cout<<"后序遍历:"<<endl;
houxu(s);
cout<<endl;
cout<<"中序遍历:"<<endl;
zhongxu(s);
cout<<endl;
return 0;
}