代码实现 #include <stdio.h> #include <stdlib.h> int partition(int arr[], int low, int high) { int temp = arr[low]; while (low<high) { while (low<high && arr[high]>=temp) { high--; } arr[low] = arr[high]; while (low<high && arr[low]<= temp) { low++; } arr[high] = arr[low]; } arr[low] = temp; return low; } void quickSort(int arr[], int low, int high) { if (low<high) { int pivot = partition(arr, low, high); quickSort(arr, low, pivot-1); quickSort(arr, pivot + 1, high); } } int main(int argc, char* argv[]) { int arr[] = {49, 38, 65, 97, 76, 13, 27, 49}; int len = sizeof(arr) / sizeof(int); quickSort(arr, 0, len - 1); for (int i = 0; i < len;++i) { printf("%d, ", arr[i]); } return 0; }