#include<iostream>
using namespace std;
struct tree
{
tree *left;
tree *right;
char on;
};
void befor(tree* w)
{
if(w!=NULL)
{
cout<<w->on;
befor(w->left);
befor(w->right);
}
}
void mid(tree* w)
{
if(w!=NULL)
{
mid(w->left);
cout<<w->on;
mid(w->right);
}
}
void createtree(tree* &w)
{
char x;
cin>>x;
if(x=='#')
{
w=NULL;
}
else
{
w=new tree;
w->on=x;
createtree(w->left);
createtree(w->right);
}
}
void last(tree *w)
{
if(w!=NULL)
{
last(w->left);
last(w->right);
cout<<w->on;
}
}
int main()
{
tree *w;
createtree(w);
befor(w);
cout<<endl;
mid(w);
cout<<endl;
last(w);
cout<<endl;
return 0;
}
二叉树建立 先序 中序 后序输出
最新推荐文章于 2023-01-12 20:55:13 发布