#include<iostream>
using namespace std;
const int N = 100010;
int n, a[N];
void quick_sort(int a[], int l, int r)
{
if (l >= r) return;
int i = l, j = r, tmp = a[l];
while (i < j)
{
while (i<j && a[j]>tmp) j--;
if (i < j) a[i++] = a[j];
while (i < j && a[i] < tmp) i++;
if (i < j) a[j--] = a[i];
}
a[i] = tmp;
quick_sort(a, l, i - 1);
quick_sort(a, i + 1, r);
}
int 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] << endl;
return 0;
}
快速排序(递归版)
最新推荐文章于 2024-08-31 15:34:19 发布