void quicksort_ints(int *t, int n) { if (n < 2) return; int p = n/2; swap_places(t, 0, p); int top = 1; for (int i = 1; i < n; i++) if (t[i] < t[0]) swap_places(t, i, top++); swap_places(t, 0, top-1); quicksort_ints(t, top-1); quicksort_ints(t+top, n-top); }
void quicksort_ints(int *array, size_t nmemb) { // Tail call quicksort while (nmemb > 1) { int pivotIndex = median_of_three_ints(array, nmemb); swap(&array[pivotIndex], &array[0]); pivotIndex = do_quicksort(array, nmemb); quicksort_ints(&array[pivotIndex+1], nmemb - 1 - pivotIndex); nmemb = pivotIndex; } }