| 151 | } |
| 152 | |
| 153 | void insert(RBTreeNode* z) |
| 154 | { |
| 155 | auto y = nil; |
| 156 | auto x = root; |
| 157 | // 找到父节点 |
| 158 | while (x != nil) { |
| 159 | y = x; |
| 160 | if (z->k < x->k) { |
| 161 | x = x->left; |
| 162 | } else { |
| 163 | x = x->right; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | z->p = y; |
| 168 | y->addChild(this, z); |
| 169 | insertFixup(z); |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | 1 父子节点之间不能出现两个连续的红节点 |