MCPcopy Create free account
hub / github.com/acm-clan/algorithm-stone / RBTree

Class RBTree

templates/rb.cpp:12–422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <time.h>
11
12class RBTree {
13private:
14 enum Color {
15 RED,
16 BLACK
17 };
18 enum Direction {
19 LEFT,
20 RIGHT
21 };
22
23public:
24 struct RBTreeNode {
25 int k = 0;
26 int v = 0;
27 RBTreeNode* p = nullptr;
28 RBTreeNode* left = nullptr;
29 RBTreeNode* right = nullptr;
30 Color color = RED;
31
32 RBTreeNode(int k, int v, Color color)
33 : k(k)
34 , v(v)
35 , color(color)
36 {
37 left = NIL;
38 right = NIL;
39 p = NIL;
40 }
41
42 void setLeft(RBTreeNode* n)
43 {
44 if (n == nullptr) {
45 printf("wrong left\n");
46 }
47 this->left = n;
48 }
49
50 void setRight(RBTreeNode* n)
51 {
52 if (n == nullptr) {
53 printf("wrong left\n");
54 }
55 right = n;
56 }
57
58 bool isLeft()
59 {
60 return this == p->left;
61 }
62
63 bool isRight()
64 {
65 return this == p->right;
66 }
67
68 RBTreeNode* brother()
69 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected