大会员可查看代码,点此开通大会员
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
char data;
struct node *left,*right;
}*t;
string s;
int len;
void creatTree(t &T)
{
if(len == s.size())
return;
char c = s[len++];
if(c == '#') T == NULL;
else{
T = new node;
T->data = c;
T->left = NULL;
T->right = NULL;
creatTree(T->left);
creatTree(T->right);
}
}
void Midorder(t T)
{
if(T != NULL)
{
Midorder(T->left);
cout<<T->data<<' ';
Midorder(T->right);
}
}
int main()
{
while(cin >> s)
{
len = 0;
t Tree;
creatTree(Tree);
Midorder(Tree);
printf("\n");
//return 0;
}
return 0;
}