int main() { int arr[] = {49, 38, 65, 97, 76, 13, 27, 49}; quickSort(arr, 0, 7); for (int i = 0; i < 8; ++i) { printf("%d ", arr[i]); } return 0; }
void quickSort(int arr[], int i, int j) { int left = i, right = j, temp; if (i < j) { temp = arr[i]; while (left < right) { while (left < right && arr[right] >= temp) --right; if (left < right) { arr[left] = arr[right]; left++; } while (left < right && arr[left] <= temp) ++left; if (left < right) { arr[right] = arr[left]; right--; } } arr[left] = temp; quickSort(arr, i, left - 1); quickSort(arr, left + 1, j); } }