快速排序
作者:
Jiarui1111
,
2023-09-25 18:26:09
,
所有人可见
,
阅读 95
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int n, a[N];
inline void quick_sort(int q[], int left, int right) {
if(left >= right) return ;
int l = left - 1, r = right + 1, x = q[left + right >> 1];
while(l < r) {
do l ++; while(q[l] < x);
do r --; while(q[r] > x);
if(l < r) swap(q[l], q[r]);
}
quick_sort(q, left, r); quick_sort(q, r + 1, right);
}
signed main() {
cin >> n;
for (int i = 1; i <= n; i ++) cin >> a[i];
quick_sort(a, 1, n);
for (int i = 1; i <= n; i ++) {
cout << a[i] << " \n"[i == n];
}
return 0;
}