Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 756acc3

Browse files
author
AndreyGeonya
committed
add heapsort jsdoc
1 parent 3ab9814 commit 756acc3

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/sorting/heapsort.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55
return a - b;
66
}
77

8-
/**
9-
* The heapsort algorithm. It's complexity is O(nlog n).
10-
*
11-
* @public
12-
*/
138
var heapSort = (function () {
149

1510
/**
1611
* Finds the correct place of given element in given max heap.
1712
*
1813
* @private
19-
* @param {array} array Array
20-
* @param {number} index Index of the element which palce in
21-
* the max heap should be found.
14+
* @param {Array} array Array.
15+
* @param {Number} index Index of the element which palce in
16+
* the max heap should be found.
2217
*/
2318
function heapify(array, index, heapSize, cmp) {
2419
var left = 2 * index + 1;
@@ -45,8 +40,8 @@
4540
* Builds max heap from given array.
4641
*
4742
* @private
48-
* @param {array} array Array which should be turned into max heap
49-
* @returns {array} array Array turned into max heap
43+
* @param {Array} array Array which should be turned into max heap.
44+
* @return {Array} array Array turned into max heap.
5045
*/
5146
function buildMaxHeap(array, cmp) {
5247
for (var i = Math.floor(array.length / 2); i >= 0; i -= 1) {
@@ -56,11 +51,20 @@
5651
}
5752

5853
/**
59-
* Heapsort. Turns the input array into max heap and after that sorts it.
54+
* Heapsort. Turns the input array into max
55+
* heap and after that sorts it.<br><br>
56+
* Time complexity: O(N log N).
57+
*
58+
* @example
59+
*
60+
* var sort = require('path-to-algorithms/src' +
61+
* '/sorting/heapsort').heapSort;
62+
* console.log(sort([2, 5, 1, 0, 4])); // [ 0, 1, 2, 4, 5 ]
6063
*
6164
* @public
62-
* @param {array} array Input array
63-
* @returns {array} array Sorted array
65+
* @module sorting/heapsort
66+
* @param {Array} array Input array.
67+
* @return {Array} Sorted array.
6468
*/
6569
return function (array, cmp) {
6670
cmp = cmp || comparator;
@@ -80,4 +84,4 @@
8084

8185
exports.heapSort = heapSort;
8286

83-
}(typeof exports === 'undefined' ? window : exports));
87+
})(typeof window === 'undefined' ? module.exports : window);

0 commit comments

Comments
 (0)