| 103 | } |
| 104 | |
| 105 | void leftRotate(RBTreeNode* x) |
| 106 | { |
| 107 | // x左移,x的右孩子y成为根节点,y的左孩子成为x的右孩子,其他不动 |
| 108 | // 看起来就像是x左移了 |
| 109 | auto y = x->right; |
| 110 | |
| 111 | // 1 x的右节点变化 |
| 112 | x->right = y->left; |
| 113 | |
| 114 | // 更新left的父节点 |
| 115 | if (y->left != nil) { |
| 116 | y->left->p = x; |
| 117 | } |
| 118 | |
| 119 | // 2 根节点变化,更换根节点 |
| 120 | y->p = x->p; |
| 121 | |
| 122 | // 如果x是根节点,将root设置为y |
| 123 | transplant(x, y); |
| 124 | |
| 125 | // 3 y的左孩子 |
| 126 | y->left = x; |
| 127 | x->p = y; |
| 128 | } |
| 129 | |
| 130 | void rightRotate(RBTreeNode* x) |
| 131 | { |
nothing calls this directly
no outgoing calls
no test coverage detected