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

Commit cde6e8a

Browse files
Update heap.js
Fix proper parent index fetching
1 parent ae41553 commit cde6e8a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Heap {
5959
*/
6060
bubbleUp() {
6161
let index = this.size - 1;
62-
const parent = (i) => Math.ceil(i / 2 - 1);
62+
const parent = (i) => Math.ceil(i / 2) - 1;
6363
while (parent(index) >= 0 && this.comparator(parent(index), index) > 0) {
6464
this.swap(parent(index), index);
6565
index = parent(index);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /