#include <stdio.h>
#include <stdlib.h>
//quick sort
void QuickSort(int r[], int first, int end)
{
if(first >= end)
return;
int mid = (first + end) / 2, i = first, j = end, x,temp;
x = r[mid];
while(1)
{
while(r[i] < x)
i++;
while(r[j] > x)
j–;
if(i >= j)
break;
temp = r[i];
r[i] = r[j];
r[j] = temp;
}
QuickSort(r,first, j - 1);
QuickSort(r,j + 1, end);
return ;
}
void ShowArray(int r[], int first, int end)
{
int i;
for (i = first; i <= end; i++)
printf("%d “, r[i]);
printf(”\n");
}
int main()
{
int n, s, t;
int r[20];
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &r[i]);
s = 1, t = n;
ShowArray(r, s, t);
QuickSort(r, s, t);
ShowArray(r, s, t);
return 0;
}
来源:CSDN
作者:山水の王也
链接:https://blog.csdn.net/weixin_42237688/article/details/104693371