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);
|
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);
|
||||||
|
|
Loading…
Reference in a new issue