-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAVL_Tree.cpp
More file actions
100 lines (100 loc) · 1.78 KB
/
Copy pathAVL_Tree.cpp
File metadata and controls
100 lines (100 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//#include<stdio.h>
//#include<algorithm>
//using namespace std;
//#pragma warning(disable:4996)
//struct Node
//{
// Node *left;
// Node *right;
// int height;
// int val;
//};
//int Height(Node* t)
//{
// return t == nullptr ? -1 : t->height;
//}
//Node * Right_Rotation(Node* t)
//{
// Node*P = t->left;
// t->left = P->right;
// P->right = t;
// t->height = max(Height(t->left), Height(t->right))+1;
// P->height = max(Height(P->left), Height(P->right))+1;
// return P;
//}
//Node* Left_Rotation(Node* t)
//{
// Node*P = t->right;
// t->right = P->left;
// P->left = t;
// t->height = max(Height(t->left), Height(t->right))+1;
// P->height = max(Height(P->left), Height(P->right))+1;
// return P;
//}
//Node* LR(Node* t)
//{
// t->left = Left_Rotation(t->left);
// t = Right_Rotation(t);
// return t;
//}
//Node* RL(Node*t)
//{
// t->right = Right_Rotation(t->right);
// t = Left_Rotation(t);
// return t;
//}
//Node* Insert(Node* t,int val)
//{
// if (t == nullptr)
// {
// t = new Node();
// t->val = val;
// }
// else
// {
// if (val < t->val)
// {
// t->left=Insert(t->left, val);
// if (Height(t->left) - Height(t->right) == 2)
// {
// if (val < t->left->val)
// {
// t = Right_Rotation(t);
// }
// else
// {
// t = LR(t);
// }
// }
// }
// else
// {
// t->right = Insert(t->right, val);
// if (Height(t->right) - Height(t->left) == 2)
// {
// if (val > t->right->val)
// {
// t = Left_Rotation(t);
// }
// else
// {
// t = RL(t);
// }
// }
// }
// }
// t->height = max(Height(t->left), Height(t->right)) + 1;
// return t;
//}
//Node* tree = nullptr;
//int main()
//{
// int N; scanf("%d", &N);
// for (int i = 0; i < N; i++)
// {
// int val; scanf("%d", &val);
// tree=Insert(tree, val);
// }
// printf("%d", tree->val);
// return 0;
//}