@@ -144,7 +144,7 @@ export function shellSort(array, base = 3) {
144
144
}
145
145
146
146
/**
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
148
148
* done for the left/right partitioned parts, and so on.
149
149
* The partition process will swap pairs of items until the left part are all smaller than pivot,
150
150
* and right part are all larger.
@@ -171,10 +171,10 @@ export function quickSortWithArray(array) {
171
171
}
172
172
173
173
/**
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
175
175
* 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" .
178
178
*
179
179
* Time complexity: O(NlogN)
180
180
* Space complexity: O(logN)
@@ -208,7 +208,7 @@ export function quickSort(array, lo = 0, hi = array.length) {
208
208
}
209
209
210
210
/**
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"
212
212
* corresponding sub-arrays back into a sorted array. The merge process ensures that the merged
213
213
* array is sorted.
214
214
*
@@ -271,11 +271,13 @@ export function heapSort(array) {
271
271
return ;
272
272
}
273
273
const isLeft = index % 2 === 1 ;
274
- const peerIndex = isLeft ? index + 1 : index - 1 ;
274
+ const firstGenerationIndex = isLeft ? index + 1 : index - 1 ;
275
275
276
276
let largest = parentIndex ;
277
277
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
+ }
279
281
if ( largest !== parentIndex ) swap ( list , largest , parentIndex ) ;
280
282
281
283
heapify ( list , index - 2 , end ) ;
0 commit comments