From c5016a0229e092d80c8973f1ce4e21c0230c15e4 Mon Sep 17 00:00:00 2001 From: Gustav Ekner Date: Sun, 6 Mar 2022 20:43:04 +0100 Subject: [PATCH] Fixed max 100 column width issue --- src/algorithms/sorting/shell-sort/ShellSort.js | 14 +++++++------- src/data-structures/heap/Heap.js | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/algorithms/sorting/shell-sort/ShellSort.js b/src/algorithms/sorting/shell-sort/ShellSort.js index 6113bc36..58859acb 100644 --- a/src/algorithms/sorting/shell-sort/ShellSort.js +++ b/src/algorithms/sorting/shell-sort/ShellSort.js @@ -12,20 +12,20 @@ export default class ShellSort extends Sort { while (gap > 0) { // Go and compare all distant element pairs. for (let i = 0; i < (array.length - gap); i += 1) { - let currentIndex = i; + let j = i; let gapShiftedIndex = i + gap; - while (currentIndex >= 0) { + while (j >= 0) { // Call visiting callback. - this.callbacks.visitingCallback(array[currentIndex]); + this.callbacks.visitingCallback(array[j]); // Compare and swap array elements if needed. - if (this.comparator.lessThan(array[gapShiftedIndex], array[currentIndex])) { - [array[currentIndex], array[gapShiftedIndex]] = [array[gapShiftedIndex], array[currentIndex]]; + if (this.comparator.lessThan(array[gapShiftedIndex], array[j])) { + [array[j], array[gapShiftedIndex]] = [array[gapShiftedIndex], array[j]]; } - gapShiftedIndex = currentIndex; - currentIndex -= gap; + gapShiftedIndex = j; + j -= gap; } } diff --git a/src/data-structures/heap/Heap.js b/src/data-structures/heap/Heap.js index b3ae7068..e12b7afc 100644 --- a/src/data-structures/heap/Heap.js +++ b/src/data-structures/heap/Heap.js @@ -95,7 +95,8 @@ export default class Heap { * @param {number} indexTwo */ swap(indexOne, indexTwo) { - [this.heapContainer[indexOne], this.heapContainer[indexTwo]] = [this.heapContainer[indexTwo], this.heapContainer[indexOne]]; + [this.heapContainer[indexOne], this.heapContainer[indexTwo]] = [ + this.heapContainer[indexTwo], this.heapContainer[indexOne]]; } /**