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

Commitb1f31cd

Browse files
committed
Fix issuetrekhleb#179.
1 parentbdf8a17 commitb1f31cd

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

‎src/data-structures/heap/Heap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default class Heap {
175175
leftChild!==null
176176
&&(
177177
parentItem===null
178-
||!this.pairIsInCorrectOrder(parentItem,this.heapContainer[indexToRemove])
178+
||this.pairIsInCorrectOrder(parentItem,this.heapContainer[indexToRemove])
179179
)
180180
){
181181
this.heapifyDown(indexToRemove);

‎src/data-structures/heap/__test__/MinHeap.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,26 @@ describe('MinHeap', () => {
169169
minHeap.remove('hey',comparator);
170170
expect(minHeap.toString()).toBe('a,bb,dddd');
171171
});
172+
173+
it('should remove values from heap and correctly re-order the tree',()=>{
174+
constminHeap=newMinHeap();
175+
176+
minHeap.add(1);
177+
minHeap.add(2);
178+
minHeap.add(3);
179+
minHeap.add(4);
180+
minHeap.add(5);
181+
minHeap.add(6);
182+
minHeap.add(7);
183+
minHeap.add(8);
184+
minHeap.add(9);
185+
186+
expect(minHeap.toString()).toBe('1,2,3,4,5,6,7,8,9');
187+
188+
minHeap.remove(2);
189+
expect(minHeap.toString()).toBe('1,4,3,8,5,6,7,9');
190+
191+
minHeap.remove(4);
192+
expect(minHeap.toString()).toBe('1,5,3,8,9,6,7');
193+
});
172194
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp