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