-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrbtree.h
More file actions
84 lines (57 loc) · 1.7 KB
/
rbtree.h
File metadata and controls
84 lines (57 loc) · 1.7 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
#ifndef DATABASEDIMA__RBTREE_H_
#define DATABASEDIMA__RBTREE_H_
#include <list>
#include <vector>
#include "student.h"
#define KEY_NOT_FOUND "Key not found in red black tree"
namespace tree {
template <typename T, typename V>
class RBTree {
private:
struct Node {
T key{};
V value{};
Node *parent{};
Node *left{};
Node *right{};
int color{};
};
Node *m_root{};
Node *m_TNULL{};
std::vector<T> m_keys{};
Node *m_search(Node *node, const T &key) const;
void m_after_delete(Node *node);
void m_transplant(Node *a, Node *b);
void m_erase(Node *node, const T &key);
void m_after_insert(Node *node);
Node *m_minimum(Node *node) const;
Node *m_maximum(Node *node) const;
void m_left_rotate(Node *node);
void m_right_rotate(Node *node);
Node *m_copy_tree(Node *from, Node *fromTNULL, Node *parent);
void m_delete_tree(Node *node);
private:
public:
RBTree();
RBTree(const RBTree &tree);
RBTree &operator=(const RBTree &tree);
~RBTree();
V &search_without_copy(const T &key);
V search(const T &key) const;
void insert(const T &key, const V &value);
void erase(const T &key);
std::vector<T> keys() const {
return m_keys;
}
void clear()
{
m_delete_tree(m_root);
m_root = m_TNULL;
}
};
}
template
class tree::RBTree<double, std::list<unsigned long long>>;
template
class tree::RBTree<std::string, std::list<unsigned long long>>;
#endif //DATABASEDIMA__RBTREE_H_