mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
Fixed max 100 column width issue
This commit is contained in:
parent
a2514b9e7f
commit
c5016a0229
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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]];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user