1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| void qsort(int *arr, int start, int end) { if (arr == NULL || start >= end) { return; } int small = start; swap(arr[start], arr[end]);
for (int i = start; i < end; ++i) { if (arr[i] < arr[end]) { if (i != small) { swap(arr[i], arr[small]); } small += 1; } }
swap(arr[small], arr[end]);
qsort(arr, start, small-1); qsort(arr, small+1, end); }
|