密码寄了 提交的代码
提交时间:2022年4月9日 10:21 语言:C++运行时间:4ms占用内存:269K
运行状态: Accepted
题目:二叉树遍历1161

大会员可查看代码,点此开通大会员

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