题目链接: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;
}

 posted on 2015-04-08 15:48  平和之心  阅读(131)  评论(0编辑  收藏  举报