File tree 2 files changed +201
-175
lines changed
2 files changed +201
-175
lines changed Original file line number Diff line number Diff line change @@ -326,6 +326,22 @@ static void quickSort(T *begin, T *end) {
326
326
quickSort (cur + 1 , end);
327
327
}
328
328
329
+ template <typename T>
330
+ static void quickSort1 (T *begin, T *end) {
331
+ if (end - begin <= 1 ) return ;
332
+
333
+ T *lo = begin + 1 , *hi = end - 1 ;
334
+ for (T *p = lo; p <= hi; ) {
335
+ if (*p < *begin) swap (*p++, *lo++);
336
+ else if (*p > *begin) swap (*p, *hi--);
337
+ else ++p;
338
+ }
339
+ swap (*begin, lo[-1 ]);
340
+
341
+ quickSort1 (begin, lo - 1 );
342
+ quickSort1 (hi + 1 , end);
343
+ }
344
+
329
345
template <typename T>
330
346
static void quickSort2 (T *begin, T *end) {
331
347
if (end - begin <= 1 ) return ;
@@ -557,6 +573,7 @@ int main() {
557
573
ITEM (mergeSort3, 0 ),
558
574
ITEM (mergeSort4, 0 ),
559
575
ITEM (quickSort, 0 ),
576
+ ITEM (quickSort1, 0 ),
560
577
ITEM (quickSort2, 0 ),
561
578
ITEM (quickSort3, 0 ),
562
579
ITEM (quickSort4, 0 ),
You can’t perform that action at this time.
0 commit comments