zxl 提交的代码
提交时间:2022年6月26日 09:48 语言:C++运行时间:4ms占用内存:269K
运行状态: Accepted
题目:二叉树遍历1161

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

                
                    #include<bits/stdc++.h>
using namespace std;
typedef struct node{
	public:
	char val;
	node *left,*right;
}*tree;
string s;
void create(tree &t,string s,int& i){
	if(i>=s.size() ){
		t=NULL;
		return;
	}else{
		char c=s[i++];
		if(c=='#'){
			t=NULL;
			return;
		}
		t=new node;
		t->val=c;
		
		t->left=NULL;
		t->right=NULL;
		create(t->left,s,i);
		create(t->right,s,i);
	}	
}
void mido(tree &t){
	if(t!=NULL){
		mido(t->left);
		cout<<t->val<<" ";
		mido(t->right);
	}
}
int main()
{
	
	string s;
	while(cin>>s){
		int i=0;
		tree t;
		create(t,s,i);
		mido(t);
		cout<<endl;
	}
	
}