-
Notifications
You must be signed in to change notification settings - Fork 3
/
AVLTree.h
62 lines (40 loc) · 996 Bytes
/
AVLTree.h
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
//
// Created by Андрей Москалёв on 2019-10-14.
//
#ifndef TREESPRESENTATION_AVLTREE_H
#define TREESPRESENTATION_AVLTREE_H
#include "Node.h"
class AVLTree {
public:
Node * root;
AVLTree() {
this->root = nullptr;
}
int height() {
return _height(root);
}
void insert(int k) {
if (_findKey(root, k) == nullptr)
root = _insert(root, k);
}
void remove(int k) {
root = _remove(root, k);
}
int maxLen() {
return _maxLen(root);
}
private:
int _height(Node * p);
int _balanceDiff(Node * p);
void _fixHeight(Node * p);
int _maxLen(Node * p);
Node * _rotateRight(Node * p);
Node * _rotateLeft(Node * q);
Node * _balance(Node * p);
Node * _insert(Node * p, int k);
Node * _findMin(Node * p);
Node * _removeMin(Node * p);
Node * _remove(Node * p, int k);
Node * _findKey(Node * p, int k);
};
#endif //TREESPRESENTATION_AVLTREE_H