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

Method insert

templates/red-black-tree.cpp:153–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 父子节点之间不能出现两个连续的红节点

Callers

nothing calls this directly

Calls 1

addChildMethod · 0.45

Tested by

no test coverage detected