Merge pull request #56 from christianbender/changed_heapSort

added let-statment
This commit is contained in:
Christian Bender
2018-03-31 00:02:01 +02:00
committed by GitHub

View File

@ -7,9 +7,9 @@
*/
Array.prototype.heapify = function (index, heapSize) {
var largest = index;
var leftIndex = 2 * index + 1;
var rightIndex = 2 * index + 2;
let largest = index;
let leftIndex = 2 * index + 1;
let rightIndex = 2 * index + 2;
if (leftIndex < heapSize && this[leftIndex] > this[largest]) {
largest = leftIndex;
@ -20,7 +20,7 @@ Array.prototype.heapify = function (index, heapSize) {
}
if (largest !== index) {
var temp = this[largest];
let temp = this[largest];
this[largest] = this[index];
this[index] = temp;
@ -35,13 +35,13 @@ Array.prototype.heapify = function (index, heapSize) {
*/
function heapSort(items) {
var length = items.length;
let length = items.length;
for (var i = Math.floor(items.length / 2) - 1; i > -1; i--) {
for (let i = Math.floor(length / 2) - 1; i > -1; i--) {
items.heapify(i, length);
}
for (var j = length -1; j > 0; j--) {
var tmp = items[0];
for (let j = length -1; j > 0; j--) {
let tmp = items[0];
items[0] = items[j];
items[j] = tmp;
items.heapify(0, j);