RE on ALL 求助
查看原帖
RE on ALL 求助
551088
FincheuwYggdrasil楼主2022/11/20 10:54

RT

#include<bits/stdc++.h>
using namespace std;
struct BinaryTree{
	char Val;
	BinaryTree* Left;
	BinaryTree* Right;
	BinaryTree(){
		Left = Right = nullptr;
	}
}*root; 
int cs;
char r,m,l;
void LOscanf(BinaryTree* root)
{
	queue<BinaryTree*>q;
	q.push(root);
	while(!q.empty())
	{
		BinaryTree* nr = q.front();
		cin >> m >> r >> l;
		nr->Val = m; 
		nr->Left->Val = l;
		nr->Right->Val = r;
		q.pop();
		if(nr->Left->Val != '*')
			q.push(nr->Left);
		if(nr->Right->Val != '*')
			q.push(nr->Right);	
	}
}
void POprintf(BinaryTree* root)
{
	printf("%c",root->Val);
	if(root->Left->Val != '*')
		POprintf(root->Left);
	if(root->Right->Val != '*')
		POprintf(root->Right);
}
int main()
{
	scanf("%d",&cs);
	LOscanf(root);
	POprintf(root);
 	return 0;
}

2022/11/20 10:54
加载中...