您的位置:首页 > 其它

nyoj 202 红黑树

2015-04-08 15:48 197 查看
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=202

一棵树左旋或者右旋,树的中序遍历保持不变
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int ls[25];
int rs[25];
int n;

void print(int id)
{
if(id == -1 || id >= n) return ;
print(ls[id]);
cout<<id<<endl;
print(rs[id]);
}

int main()
{
freopen("d:\\in.txt", "r", stdin);
int t;
cin>>t;
while(t--)
{
memset(ls, 0, sizeof(ls));
memset(rs, 0, sizeof(rs));
int a, b, c;
cin>>n;
for(int i=0; i<n; i++){
cin>>a>>b>>c;
ls[a]= b;
rs[a] = c;
}
int m;
cin>>m;
while(m--) cin>>a>>b;
print(0);
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: