連結:click here
題意:題目其實很簡單,繞一大圈,原來就是叫你輸出輸出中序周遊,Orz~~~紅黑樹經過旋轉後中序周遊其實是不變的,是以與下面的旋轉沒有關系~~--- _ --.
思路:直接數組模拟,或用結構體:包含(資料域,左子樹,右子樹)
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=20;
const int inf =0x3f3f3f3f;
int N,F,D;
int leftt[maxn],rightt[maxn];
struct node
{
int data;
int leftchild,rightchild;
} tree[maxn];
void inorder(int key)
{
if(key!=-1)
{
inorder(tree[key].leftchild);
printf("%d\n",tree[key].data);
inorder(tree[key].rightchild);
}
}
int main()
{
int T,root,ld,rd;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d%d%d",&root,&ld,&rd);
tree[root].data=root;
tree[root].leftchild=ld;
tree[root].rightchild=rd;
// scanf("%d%d%d",&tree[i].data,&tree[i].leftchild,&tree[i].rightchild);
}
int m,ve,mv;
scanf("%d",&m);
while(m--)
{
scanf("%d%d",&ve,&mv);
}
inorder(0);
printf("\n");
}
return 0;
}