# 1066. Root of AVL Tree (25)【AVL树】——PAT (Advanced Level) Practise

## 题目信息

1066. Root of AVL Tree (25)

An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property. Figures 1-4 illustrate the rotation rules.    Now given a sequence of insertions, you are supposed to tell the root of the resulting AVL tree.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer N (<=20) which is the total number of keys to be inserted. Then N distinct integer keys are given in the next line. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print ythe root of the resulting AVL tree in one line.

Sample Input 1:

5

88 70 61 96 120

Sample Output 1:

70

Sample Input 2:

7

88 70 61 96 120 90 65

Sample Output 2:

88

## AC代码

``````#include <cstdio>
#include <algorithm>
using namespace std;
struct node{
node *left, *right;
int v, w;
node(int value, node* l, node* r) : v(value), left(l), right(r), w(0) {}
};
node *nil = new node(0, NULL, NULL);
node *head = nil;
node *t = head->right;
}
node *t = head->left;
}
void insert(node *&head, int v){
if (head == nil){
head = new node(v, nil, nil);
}else if (v > head->v){
if (v > head->right->v){
}else{
}
}
}else{
if (v <= head->left->v){
}else{
}
}
}
}
int main()
{
int n, a;
scanf("%d", &n);
while (n--){
scanf("%d", &a);
}
return 0;
}`````` 《10云方》与方块来次消除大战!