Skip to content

Commit eca6d26

Browse files
committed
Add left and right rotations
1 parent bcf14c3 commit eca6d26

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/data-structures/red-black-tree.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,19 @@
5050
RBTree.prototype._rotateLeft = function (node) {
5151
var x = node.getRight();
5252
if (x !== null) {
53-
var temp = x.left;
54-
node.right = temp;
55-
x.left = node;
53+
var temp = x.getLeft();
54+
node.setRight(temp);
55+
x.setLeft(node);
56+
}
57+
return x;
58+
};
59+
60+
RBTree.prototype._rotateRight = function (node) {
61+
var x = node.getLeft();
62+
if (x !== null) {
63+
var temp = x.getRight();
64+
node.setLeft(temp);
65+
x.setRight(node);
5666
}
5767
return x;
5868
};

0 commit comments

Comments
 (0)