#include<stdio.h>
int num[1000];
void quick_sort(int left,int right)
{
if (left >= right)return;
int l = left - 1, r = right + 1, x = num[(left + right) / 2];
while (l < r)
{
do l++; while (num[l] < x);
do r--; while (num[r] > x);
if (l < r)
{
int c = num[l]; num[l] = num[r]; num[r] = c;
}
}
quick_sort(left, r);
quick_sort(r + 1, right);
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &num[i]);
}
quick_sort(0, n - 1);
for (int i = 0; i < n; i++)
{
printf("%d ",num[i]);
}
}
快速排序(快排)
最新推荐文章于 2024-11-18 16:46:21 发布