大会员可查看代码,点此开通大会员
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
char data;
node *l,*r;
node(char c):data(c),l(NULL),r(NULL){}
}*tree;
tree create(string s,int *loc){
if(s[*loc]=='\0'){return NULL;}
if(s[*loc]=='#'){
return NULL;
}
tree root = new node(s[*loc]);
if(s[*loc]!='\0'){
(*loc)++;
root->l=create(s,loc);
}
if(s[*loc]!='\0'){
(*loc)++;
root->r=create(s,loc);
}
return root;
}
void in(tree t){
if(t!=NULL){
in(t->l);
cout<<t->data<<" ";
in(t->r);
}
}
int main(){
string s;
while(cin>>s){
int loc=0;
tree root;
root= create(s, &loc);
in(root);
cout << endl;
}
return 0;
}