Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitfe9fd72

Browse 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 parentd2f065a commitfe9fd72

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@
7575

7676
functionupdateChild(node,newChild){
7777
letparent=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-
returnparent;
78+
if(parent.right===node){
79+
parent.right=newChild;
80+
newChild.parent=parent;
81+
}elseif(parent.left===node){
82+
parent.left=newChild;
83+
newChild.parent=parent;
84+
}
85+
if(newChild!==Nil){
86+
returnnewChild;
8787
}
88-
returnnewChild;
88+
returnparent;
8989
}
9090

9191
functionLeftRotate(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
returnremovedNode;
278274
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp