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