密码寄了 提交的代码
提交时间: 2022 四月
语言: C++
运行时间: 4ms
占用内存: 269K
Accepted
代码内容

登录之后查看代码,点此登录账号

#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;
}