#include<iostream>
using namespace std;
int n;
const int N = 100010;
int arr[N];
void quick_sort(int l, int r) {
if (l >= r)return;
int i = l - 1, j = r + 1;
int t = arr[l + r >> 1];
while (i < j) {
do i++; while (arr[i] < t);
do j--; while (arr[j] > t);
if (i < j)swap(arr[i], arr[j]);
}
quick_sort(l, j);
quick_sort(j + 1, r);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)scanf("%d", &arr[i]);
quick_sort(0, n - 1);
for (int i = 0; i < n; i++)printf("%d ", arr[i]);
}
快排板子
最新推荐文章于 2024-11-03 21:27:26 发布