#define _CRT_SECURE_NO_WARNINGS 1 #include <iostream> using namespace std; int n = 0; const int N = 100000 + 10; int arr[N]; //快速排序 void quick_sort(int arr[], int l, int r) { if (l >= r) return; int temp = arr[(l+ r) >> 1]; int i = l - 1, j = r + 1; while (i < j) { do i++; while (arr[i] < temp); do j--; while (arr[j] > temp); //注意,你要写成是j++ if (i < j) swap(arr[i], arr[j]); } quick_sort(arr, l, j); quick_sort(arr, j+1, r); //注意上面是j,下面就要写成j+1 } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &arr[i]); quick_sort(arr, 0, n - 1); for (int i = 0; i < n; i++) printf("%d ", arr[i]); }