Skip to content

Commit 28490dd

Browse files
committed
minor
1 parent be86110 commit 28490dd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/_.general/sorting.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export function shellSort(array, base = 3) {
144144
}
145145

146146
/**
147-
* Quick sort, sorted by performing a partition process for a chosen pivot item, and the same is
147+
* Quick sort, sorted by performing a "partition" process for a chosen pivot item, and the same is
148148
* done for the left/right partitioned parts, and so on.
149149
* The partition process will swap pairs of items until the left part are all smaller than pivot,
150150
* and right part are all larger.
@@ -171,10 +171,10 @@ export function quickSortWithArray(array) {
171171
}
172172

173173
/**
174-
* Quick sort, sorted by performing a partition process for a chosen pivot item, and the same is
174+
* Quick sort, sorted by performing a "partition" process for a chosen pivot item, and the same is
175175
* done for the left/right partitioned parts, and so on.
176-
* The partition process will swap pairs of items until the left part are all smaller than pivot,
177-
* and right part are all larger.
176+
* The partition process will swap pairs of items until the left part are "all smaller than pivot",
177+
* and right part are "all larger".
178178
*
179179
* Time complexity: O(NlogN)
180180
* Space complexity: O(logN)
@@ -208,7 +208,7 @@ export function quickSort(array, lo = 0, hi = array.length) {
208208
}
209209

210210
/**
211-
* Merge sort, sorted by recursively dividing the array into two sub-arrays and merging
211+
* Merge sort, sorted by recursively dividing the array into two sub-arrays and "merging"
212212
* corresponding sub-arrays back into a sorted array. The merge process ensures that the merged
213213
* array is sorted.
214214
*
@@ -271,11 +271,13 @@ export function heapSort(array) {
271271
return;
272272
}
273273
const isLeft = index % 2 === 1;
274-
const peerIndex = isLeft ? index + 1 : index - 1;
274+
const firstGenerationIndex = isLeft ? index + 1 : index - 1;
275275

276276
let largest = parentIndex;
277277
if (list[index] > list[largest]) largest = index;
278-
if (peerIndex <= end && list[peerIndex] > list[largest]) largest = peerIndex;
278+
if (firstGenerationIndex <= end && list[firstGenerationIndex] > list[largest]) {
279+
largest = firstGenerationIndex;
280+
}
279281
if (largest !== parentIndex) swap(list, largest, parentIndex);
280282

281283
heapify(list, index - 2, end);

0 commit comments

Comments
 (0)