-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrbtree.h
More file actions
56 lines (45 loc) · 1.22 KB
/
rbtree.h
File metadata and controls
56 lines (45 loc) · 1.22 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
#ifndef RBTREE_H
#define RBTREE_H
#include <ostream>
#include <vector>
using std::ostream, std::vector;
class RBTree {
public:
bool show_null_leaves;
RBTree();
~RBTree();
struct Node {
enum Color { BLACK, RED };
int inf;
Node *left, *right;
Node *parent;
Color color;
Node(const int value);
};
void insert(const int value);
void erase(const int value);
RBTree::Node *find(const int value) const;
int max() const;
int min() const;
void clear();
friend ostream &operator<<(ostream &ostream, const RBTree &tr);
private:
Node *root;
static const Node *NIL;
void right_rotate(Node *p);
void left_rotate(Node *p);
void insert_fixup(Node *node);
void erase_node(Node *node);
void erase_fixup(Node *node);
static Node *find(Node *node, const int value);
static Node *max(Node *node);
static Node *min(Node *node);
static void clear(Node *node);
static int height(const Node *node);
void make_array(
vector<vector<const Node *>> &array, const Node *node, const int depth = 0,
const int count = 1
) const;
friend ostream &operator<<(ostream &ostream, const Node *node);
};
#endif