求助,蒟蒻要调炸了
查看原帖
求助,蒟蒻要调炸了
556110
_Timeless_楼主2022/7/18 20:34
#include <iostream>

using namespace std;

int a[100002][2];
int x, y, z, root;
int n;

void preorder(char c)
{
	cout << c;
	if(a[c][0] != '*')
	{
		preorder(a[c][0]);
	}
	if(a[c][1] != '*')
	{
		preorder(a[c][1]);
	}
}

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> x >> y >> z;
		if(i == 1)
		{
			root = x;
		}
		a[x][0] = y;
		a[x][1] = z;
	}
	preorder(root);
	return 0;
}
2022/7/18 20:34
加载中...