DADFISH 提交的代码
提交时间:2022年6月3日 23:38 语言:C++运行时间:0ms占用内存:272K
运行状态: Accepted
题目:二叉树遍历1161

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

                
                    #include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include <iomanip>
#include <map>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

struct node
{
	char ch;
	node* left;
	node* right;
};

string s1;
int len;

void construct_tree(node* &n)
{
	if (len == s1.length())
	{
		return;
	}
	char ch = s1[len++];
	if (ch == '#')
	{
		n = nullptr;
		return;
	}
	n = new node();
	n->ch = ch;
	n->left = nullptr;
	n->right = nullptr;
	construct_tree(n->left);
	construct_tree(n->right);
}

void inorder(node* n)
{
	if (n == nullptr)
	{
		return;
	}
	inorder(n->left);
	cout << n->ch << " ";
	inorder(n->right);
}

using ll = long long;

int main()
{
	ios::sync_with_stdio(false);

	while (cin >> s1)
	{
		node* root;
		len = 0;
		construct_tree(root);
		inorder(root);
		cout << endl;
	}
	
	return 0;
}