diff --git a/node.js b/node.js index 45daf0f..2c3082e 100644 --- a/node.js +++ b/node.js @@ -36,7 +36,7 @@ function nodeDifferences(node) { return [r - nodeRank(left), r - nodeRank(right)]; } -function rotateRight(x) { +function rotateRight(x, t) { let parent = x.parent; let y = x.left; // let z = x.right; @@ -47,6 +47,8 @@ function rotateRight(x) { } else { parent.right = y; } + } else if (t) { + t.root = y; } x.left = y.right; @@ -61,7 +63,7 @@ function rotateRight(x) { return y; } -function rotateLeft(x) { +function rotateLeft(x, t) { let parent = x.parent; // let y = x.left; let z = x.right; @@ -72,6 +74,8 @@ function rotateLeft(x) { } else { parent.right = z; } + } else if (t) { + t.root = z; } x.right = z.left;