-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvlTree.h
More file actions
38 lines (34 loc) · 688 Bytes
/
AvlTree.h
File metadata and controls
38 lines (34 loc) · 688 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
#pragma once
#include <fstream>
#include <string>
struct Node
{
Node() = delete;
Node(int v, Node* l, Node* r);
int value;
Node* leftChild = nullptr;
Node* rightChild = nullptr;
int height();
};
class AVLTree
{
public:
AVLTree();
bool Build(std::string filename);
void Insert(int number);
bool Delete(int number);
bool Search(int number) const;
int GetSize() const;
int GetMin() const;
private:
Node* Insert(Node* n, int value);
Node* Delete(Node* n, int value, bool& found);
Node* BalanceNode(Node* n);
Node* RightRotation(Node* n);
Node* LeftRotation(Node* n);
Node* MinNode(Node* n) const;
int nodeBalanceFactor(Node* n);
private:
Node* root;
int elements;
};