-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.h
More file actions
38 lines (38 loc) · 833 Bytes
/
tree.h
File metadata and controls
38 lines (38 loc) · 833 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 <optional>
namespace tree {
class Node {
public:
int value;
Node* left;
Node* right;
Node(int value);
};
class BinaryTree {
protected:
Node* root;
virtual Node* insertNode(Node* node, int value);
void deleteTree(Node* node);
public:
std::optional<int> binarySearch(Node* node, int value);
BinaryTree();
virtual ~BinaryTree();
Node* getRoot();
virtual void insert(int value);
// Deep First Search (DFS)
void inOrder(Node* root);
void postOrder(Node* root);
void preOrder(Node* root);
};
class AVLTree : public BinaryTree {
private:
int height(Node* node);
int balanceFactor(Node* node);
Node* rotateLeft(Node* node);
Node* rotateRight(Node* node);
Node* insertNode(Node* node, int value) override;
public:
AVLTree();
void insert(int value) override;
};
}