finish writing and prepare to fix bugs
This commit is contained in:
@ -243,7 +243,7 @@ class map {
|
||||
successor->color = color_of_node;
|
||||
if (parent_of_successor == node) {
|
||||
successor->left = left_of_node;
|
||||
successor->right = right_of_node;
|
||||
successor->right = node;
|
||||
successor->SetChildrensParent();
|
||||
successor->parent = parent_of_node;
|
||||
path_of_node = successor;
|
||||
@ -264,8 +264,8 @@ class map {
|
||||
}
|
||||
}
|
||||
void DeleteFixUp(RedBlackTreeNodeType *&tree_root) {
|
||||
assert(this->left == nullptr && this->right == nullptr);
|
||||
assert(this->color == RedBlackTreeColorType::BLACK);
|
||||
if (this == tree_root) return;
|
||||
RedBlackTreeNodeType *sibling = GetSibling();
|
||||
assert(sibling != nullptr);
|
||||
if (sibling->color == RedBlackTreeColorType::RED) {
|
||||
@ -294,8 +294,6 @@ class map {
|
||||
(distant_nephew == nullptr ||
|
||||
distant_nephew != nullptr && distant_nephew->color == RedBlackTreeColorType::BLACK)) {
|
||||
// Case 2
|
||||
assert(close_nephew == nullptr);
|
||||
assert(distant_nephew == nullptr);
|
||||
sibling->color = RedBlackTreeColorType::RED;
|
||||
this->parent->color = RedBlackTreeColorType::BLACK;
|
||||
return;
|
||||
@ -305,8 +303,6 @@ class map {
|
||||
(distant_nephew == nullptr ||
|
||||
distant_nephew != nullptr && distant_nephew->color == RedBlackTreeColorType::BLACK)) {
|
||||
// Case 3
|
||||
assert(close_nephew == nullptr);
|
||||
assert(distant_nephew == nullptr);
|
||||
sibling->color = RedBlackTreeColorType::RED;
|
||||
this->parent->DeleteFixUp(tree_root);
|
||||
return;
|
||||
@ -328,13 +324,11 @@ class map {
|
||||
assert(distant_nephew != nullptr && distant_nephew->color == RedBlackTreeColorType::RED);
|
||||
// Then it must be Case 5
|
||||
if (this == parent->left) {
|
||||
sibling->color = parent->color;
|
||||
parent->color = RedBlackTreeColorType::BLACK;
|
||||
std::swap(sibling->color, parent->color);
|
||||
distant_nephew->color = RedBlackTreeColorType::BLACK;
|
||||
parent->RotateLeft(tree_root);
|
||||
} else {
|
||||
sibling->color = parent->color;
|
||||
parent->color = RedBlackTreeColorType::BLACK;
|
||||
std::swap(sibling->color, parent->color);
|
||||
distant_nephew->color = RedBlackTreeColorType::BLACK;
|
||||
parent->RotateRight(tree_root);
|
||||
}
|
||||
@ -351,7 +345,7 @@ class map {
|
||||
RedBlackTreeNodeType *successor = pos->right;
|
||||
while (successor->left != nullptr) successor = successor->left;
|
||||
SwapNodeWithItsSuccessor(pos, successor, tree_root);
|
||||
DeleteNode(successor, tree_root);
|
||||
DeleteNode(pos, tree_root);
|
||||
return;
|
||||
}
|
||||
if (pos->left == nullptr && pos->right == nullptr) {
|
||||
|
Reference in New Issue
Block a user