Skip to content

Commit d887f98

Browse files
committed
UPdated to have prints for testing heapsort
1 parent a4dbc68 commit d887f98

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/sorting/heapsort.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* @param {function} cmp Comparison function.
1919
*/
2020
function heapify(array, index, heapSize, cmp) {
21+
console.log("heapifying");
22+
2123
var left = 2 * index + 1;
2224
var right = 2 * index + 2;
2325
var largest = index;
@@ -36,6 +38,10 @@
3638
array[largest] = temp;
3739
heapify(array, largest, heapSize, cmp);
3840
}
41+
42+
console.log(array);
43+
44+
3945
}
4046

4147
/**
@@ -50,6 +56,7 @@
5056
for (var i = Math.floor(array.length / 2); i >= 0; i -= 1) {
5157
heapify(array, i, array.length, cmp);
5258
}
59+
5360
return array;
5461
}
5562

@@ -84,10 +91,17 @@
8491
size -= 1;
8592
heapify(array, 0, size, cmp);
8693
}
94+
console.log(array);
8795
return array;
8896
};
8997
}());
9098

9199
exports.heapSort = heapSort;
92100

93101
})(typeof window === 'undefined' ? module.exports : window);
102+
103+
104+
105+
106+
107+

0 commit comments

Comments
 (0)