#include <iostream>
using namespace std;
struct BTreeNode
{
char val;
BTreeNode *lf;
BTreeNode *rf;
};
void init(BTreeNode* &p) //指针引用
{
char ch;
cin>>ch;
if(ch != '!')
{
p = new BTreeNode;
p->val = ch;
init(p->lf);
init(p->rf);
}else
{
p = NULL;
}
}
void pre(BTreeNode *p)
{
if(p)
{
cout<<p->val;
pre(p->lf);
pre(p->rf);
}
}
void ino(BTreeNode *p)
{
if(p)
{
ino(p->lf);
cout<<p->val;
ino(p->rf);
}
}
void pro(BTreeNode *p)
{
if(p)
{
pro(p->lf);
pro(p->rf);
cout<<p->val;
}
}
int main()
{
BTreeNode *p;
init(p);
pre(p);
cout<<endl;
ino(p);
cout<<endl;
pro(p);
cout<<endl;
return 0;
}
运行结果如下: