Thomas Cormen save us
This commit is contained in:
parent
cec8293382
commit
2d8a36e932
1 changed files with 16 additions and 22 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue