feat: fix root in rotation functions
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
948f47de3b
commit
df787476ac
1 changed files with 6 additions and 2 deletions
8
node.js
8
node.js
|
@ -36,7 +36,7 @@ function nodeDifferences(node) {
|
||||||
return [r - nodeRank(left), r - nodeRank(right)];
|
return [r - nodeRank(left), r - nodeRank(right)];
|
||||||
}
|
}
|
||||||
|
|
||||||
function rotateRight(x) {
|
function rotateRight(x, t) {
|
||||||
let parent = x.parent;
|
let parent = x.parent;
|
||||||
let y = x.left;
|
let y = x.left;
|
||||||
// let z = x.right;
|
// let z = x.right;
|
||||||
|
@ -47,6 +47,8 @@ function rotateRight(x) {
|
||||||
} else {
|
} else {
|
||||||
parent.right = y;
|
parent.right = y;
|
||||||
}
|
}
|
||||||
|
} else if (t) {
|
||||||
|
t.root = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
x.left = y.right;
|
x.left = y.right;
|
||||||
|
@ -61,7 +63,7 @@ function rotateRight(x) {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
function rotateLeft(x) {
|
function rotateLeft(x, t) {
|
||||||
let parent = x.parent;
|
let parent = x.parent;
|
||||||
// let y = x.left;
|
// let y = x.left;
|
||||||
let z = x.right;
|
let z = x.right;
|
||||||
|
@ -72,6 +74,8 @@ function rotateLeft(x) {
|
||||||
} else {
|
} else {
|
||||||
parent.right = z;
|
parent.right = z;
|
||||||
}
|
}
|
||||||
|
} else if (t) {
|
||||||
|
t.root = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
x.right = z.left;
|
x.right = z.left;
|
||||||
|
|
Loading…
Reference in a new issue