-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAVLTree.h
More file actions
48 lines (39 loc) · 998 Bytes
/
Copy pathAVLTree.h
File metadata and controls
48 lines (39 loc) · 998 Bytes
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
#ifndef AVLTREE_H
#define AVLTREE_H
#include <cstring>
#include <string>
using namespace std;
class AVLTree {
private:
struct Node {
int value;
Node* left;
Node* right;
int height;
Node(int val) : value(val), left(NULL), right(NULL), height(1) {}
};
Node* root;
int currentSize;
Node* insert(Node* node, int value);
Node* remove(Node* node, int value);
Node * findMin(Node* node) const;
Node* removeMin(Node* node);
Node* balance(Node* node);
int getHeight(Node* node);
int getBalanceFactor(Node* node);
Node* rotateRight(Node* y);
Node* rotateLeft(Node* x);
void printInOrder(Node* node) const;
public:
AVLTree();
~AVLTree();
void insert(int value);
void remove(int value);
bool isEmpty() const;
int getSize() const;
void printInOrder() const;
void destroyTree(Node* node);
int getMin() const;
string searchAVL(int value) const;
};
#endif // AVLTREE_H