mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +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.
|
||||
if (this.comparator.lessThan(array[gapShiftedIndex], array[currentIndex])) {
|
||||
const tmp = array[currentIndex];
|
||||
array[currentIndex] = array[gapShiftedIndex];
|
||||
array[gapShiftedIndex] = tmp;
|
||||
[array[currentIndex], array[gapShiftedIndex]] = [array[gapShiftedIndex], array[currentIndex]];
|
||||
}
|
||||
|
||||
gapShiftedIndex = currentIndex;
|
||||
|
@ -95,9 +95,7 @@ export default class Heap {
|
||||
* @param {number} indexTwo
|
||||
*/
|
||||
swap(indexOne, indexTwo) {
|
||||
const tmp = this.heapContainer[indexTwo];
|
||||
this.heapContainer[indexTwo] = this.heapContainer[indexOne];
|
||||
this.heapContainer[indexOne] = tmp;
|
||||
[this.heapContainer[indexOne], this.heapContainer[indexTwo]] = [this.heapContainer[indexTwo], this.heapContainer[indexOne]];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user