#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int a[10], len; // 0x100000A
void quick_sort(int l = 0, int r = len) {
if (l == r) {
return;
}
int key = a[l + abs(rand()) % (r - l + 1)], i = l, j = r - 1;
while (i + 1 < j) {
if (a[i] <= key) {
i ++;
}
if (a[j] > key) {
j --;
}
if (a[j] <= key) {
swap(a[i], a[j]);
i ++;
}
if (a[i] > key) {
swap(a[i], a[j]);
j --;
}
}
quick_sort(l, i);
quick_sort(j, r);
}
int main() {
cin >> len;
for (int i = 0; i < len; i ++) {
cin >> a[i];
}
quick_sort();
for (int i = 0; i < len; i ++) {
cout << a[i] << ' ';
}
return 0;
}
这代码死循环还RE,怎么改?