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

Commit19a12da

Browse files
committed
Fixes of the Nil pointer problem,
testing push 10000 elements at the end and get the 10000 elements and check it.
1 parent46f29d4 commit19a12da

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
NL CL
108108
*/
109109
node.right=childNode.left;
110-
node.right.parent=node;
110+
if(node.right!==Nil)node.right.parent=node;
111111
childNode.left=node;
112112
updateChild(node,childNode)//Access node.parent
113113
node.parent=childNode;
@@ -132,7 +132,7 @@
132132
CR NR
133133
*/
134134
node.left=childNode.right;
135-
node.left.parent=node;
135+
if(node.left!==Nil)node.left.parent=node;
136136
childNode.right=node;
137137
updateChild(node,childNode)//Access node.parent
138138
node.parent=childNode;
@@ -171,6 +171,7 @@
171171
node=node.left;
172172
}else{
173173
pos-=node.left.size;
174+
--pos;//The node element should be decrement by 1
174175
node=node.right;
175176
}
176177
}

‎test/data-structures/size-balanced-tree.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,17 @@ describe('SBTree', function () {
8181
expect(root.left).toBe(Nil);
8282
updateChild(Nil,right);
8383
expect(right.parent).toBe(Nil);
84+
checkNil();
85+
});
86+
87+
it('push and get 100000 elements',function(){
88+
varsTree=newSBTree();
89+
for(vari=0;i<100000;++i){
90+
sTree.push(i);
91+
}
92+
checkNil();
93+
for(vari=0;i<100000;++i){
94+
expect(sTree.get(i).value).toBe(i);
95+
}
8496
});
8597
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp