mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-10 11:09:43 +08:00
Changed swap in ShellSort and Heap
This commit is contained in:
parent
822d4e3ac7
commit
a2514b9e7f
@ -21,9 +21,7 @@ export default class ShellSort extends Sort {
|
|||||||
|
|
||||||
// Compare and swap array elements if needed.
|
// Compare and swap array elements if needed.
|
||||||
if (this.comparator.lessThan(array[gapShiftedIndex], array[currentIndex])) {
|
if (this.comparator.lessThan(array[gapShiftedIndex], array[currentIndex])) {
|
||||||
const tmp = array[currentIndex];
|
[array[currentIndex], array[gapShiftedIndex]] = [array[gapShiftedIndex], array[currentIndex]];
|
||||||
array[currentIndex] = array[gapShiftedIndex];
|
|
||||||
array[gapShiftedIndex] = tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gapShiftedIndex = currentIndex;
|
gapShiftedIndex = currentIndex;
|
||||||
|
@ -95,9 +95,7 @@ export default class Heap {
|
|||||||
* @param {number} indexTwo
|
* @param {number} indexTwo
|
||||||
*/
|
*/
|
||||||
swap(indexOne, indexTwo) {
|
swap(indexOne, indexTwo) {
|
||||||
const tmp = this.heapContainer[indexTwo];
|
[this.heapContainer[indexOne], this.heapContainer[indexTwo]] = [this.heapContainer[indexTwo], this.heapContainer[indexOne]];
|
||||||
this.heapContainer[indexTwo] = this.heapContainer[indexOne];
|
|
||||||
this.heapContainer[indexOne] = tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user