nyist 202 红黑树(二叉树中序遍历)

时间:2023-03-09 15:02:00
nyist 202 红黑树(二叉树中序遍历)

旋转对中序遍历没有影响,直接中序输出即可。

#include <iostream>
#include <cstdio>
using namespace std;
int n;
struct Shu
{
int left,rigth;
}shu[1000005];
int zhong(int id)
{
if(id>=0)
{
zhong(shu[id].left);
cout<<id<<endl;
zhong(shu[id].rigth);
}
}
int main(int argc, char *argv[])
{
int t,i,j,x,y,z,m;
cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<n;i++)
{
cin>>x>>y>>z;
shu[x].left=y;
shu[x].rigth=z;
}
cin>>m;
for(i=0;i<m;i++) cin>>x>>y;
zhong(0);
}
return 0;
}