#include<iostream>
using namespace std;
int a[100005], b[100005], n, m;
void very_quick_sort(int l, int r, int p, int q) {
if (l >= r || p > q) {
return;
}
int mid = (l + r) / 2;
int p0 = p - 1;
int q0 = q + 1;
for (int i = p; i <= q; i ++) {
if (a[i] > mid) b[++ p0] = a[i];
else b[-- q0] = a[i];
}
for (int i = p; i <= q; i ++)
a[i] = b[i];
very_quick_sort(mid + 1, r, p, p0);
very_quick_sort(l, mid, q0, q);
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i ++)
cin >> a[i];
very_quick_sort(1, m, 1, n);
for (int i = 1; i <= n; i ++
cout << a[i] << " ";
cout << endl;
return 0;
}
共 2 条回复
某种比较快的排序方法(应该是快排或者归并排序
哪位知道