| 10 | #include <time.h> |
| 11 | |
| 12 | class RBTree { |
| 13 | private: |
| 14 | enum Color { |
| 15 | RED, |
| 16 | BLACK |
| 17 | }; |
| 18 | enum Direction { |
| 19 | LEFT, |
| 20 | RIGHT |
| 21 | }; |
| 22 | |
| 23 | public: |
| 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 | { |
nothing calls this directly
no outgoing calls
no test coverage detected