Thomas Cormen save us

This commit is contained in:
jacekpoz 2024-06-05 23:43:04 +02:00
parent cec8293382
commit 2d8a36e932
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -278,19 +278,16 @@ impl RedBlackTree {
parent.set_colour(Black);
grandparent.set_colour(Red);
node = grandparent;
continue;
}
} else {
if parent.right() == node {
self.rotate_left(parent);
let temp = parent;
parent = node;
node = temp;
node = parent;
self.rotate_left(node);
}
parent.set_colour(Black);
grandparent.set_colour(Red);
self.rotate_right(grandparent);
}
} else {
let mut uncle = grandparent.left();
if !uncle.is_null() && uncle.colour() == Red {
@ -298,14 +295,10 @@ impl RedBlackTree {
parent.set_colour(Black);
grandparent.set_colour(Black);
node = grandparent;
continue;
}
} else {
if parent.left() == node {
self.rotate_right(parent);
let temp = parent;
parent = node;
node = temp;
node = parent;
self.rotate_right(node);
}
parent.set_colour(Black);
@ -313,6 +306,7 @@ impl RedBlackTree {
self.rotate_left(grandparent);
}
}
}
self.root.set_colour(Black);
}