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 {
node = parent;
self.rotate_left(node);
}
if parent.right() == node {
self.rotate_left(parent);
let temp = parent;
parent = node;
node = temp;
parent.set_colour(Black);
grandparent.set_colour(Red);
self.rotate_right(grandparent);
}
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,19 +295,16 @@ impl RedBlackTree {
parent.set_colour(Black);
grandparent.set_colour(Black);
node = grandparent;
continue;
}
} else {
if parent.left() == node {
node = parent;
self.rotate_right(node);
}
if parent.left() == node {
self.rotate_right(parent);
let temp = parent;
parent = node;
node = temp;
parent.set_colour(Black);
grandparent.set_colour(Red);
self.rotate_left(grandparent);
}
parent.set_colour(Black);
grandparent.set_colour(Red);
self.rotate_left(grandparent);
}
}
self.root.set_colour(Black);