Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe9fd72

Browse filesBrowse files
committed
Getting the maintainNode to be the leaf-most node, so that the updateSize would always be right and
the rotate always working.
1 parent d2f065a commit fe9fd72
Copy full SHA for fe9fd72

1 file changed

+11-15Lines changed: 11 additions & 15 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/data-structures/size-balanced-tree.js‎

Copy file name to clipboardExpand all lines: src/data-structures/size-balanced-tree.js
+11-15Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@
7575

7676
function updateChild(node, newChild) {
7777
let parent = node.parent;
78-
if (parent !== Nil) {
79-
if (parent.right === node) {
80-
parent.right = newChild;
81-
newChild.parent = parent;
82-
} else {
83-
parent.left = newChild;
84-
newChild.parent = parent;
85-
}
86-
return parent;
78+
if (parent.right === node) {
79+
parent.right = newChild;
80+
newChild.parent = parent;
81+
} else if (parent.left === node) {
82+
parent.left = newChild;
83+
newChild.parent = parent;
84+
}
85+
if (newChild !== Nil) {
86+
return newChild;
8787
}
88-
return newChild;
88+
return parent;
8989
}
9090

9191
function LeftRotate(node, childNode) {
@@ -267,12 +267,8 @@
267267
updateChild(node, node.left)
268268
LRM.right = node.right
269269
LRM.right.parent = LRM;
270-
maintainNode = LRM;
270+
maintainNode = node.right;
271271
}
272-
if (maintainNode !== Nil) {
273-
maintainNode.updateSize();
274-
}
275-
276272
this._root = maintainSizeBalancedTree(maintainNode);
277273
return removedNode;
278274
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.