Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f32eea5

Browse files
committed
Update insertion
1 parent b7133eb commit f32eea5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@
6363
} else if (node.getKey() < key) {
6464
node.setRight(this._put(key, value, node.getRight()));
6565
}
66-
if (this.isRed(node.getRight())) {
66+
if (this.isRed(node.getRight()) && !this.isRed(node.getLeft())) {
6767
newRoot = this._rotateLeft(node);
6868
}
6969
if (this.isRed(node.getLeft()) && this.isRed(node.getLeft().getLeft())) {
7070
newRoot = this._rotateRight(node);
7171
}
7272
if (this.isRed(node.getLeft()) && this.isRed(node.getRight())) {
73-
this._flipColors();
73+
this._flipColors(node);
7474
}
7575
return newRoot;
7676
};

test/data-structures/red-black-tree.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('RBTree', function () {
6161
expect(tree._root._left).not.toBeNull();
6262
expect(tree._root._left.isRed()).toBeTruthy();
6363
tree.put(2, 'baz');
64-
expect(tree._root._left).not.toBeNull();
64+
expect(tree._root._right).not.toBeNull();
6565
});
6666

6767
});

0 commit comments

Comments
 (0)