//快速排序算法代码
#include<stdio.h>
#define MAXSIZE 20
typedef struct
{
int length;
int r[MAXSIZE+1];
}RecordList;
int QKpass(RecordList L, int low, int high)
{
L->r[0] = L->r[low];
while (low < high)
{
while (low < high && L->r[high] >= L->r[0]) high–;
L->r[low]=L->r[high];
while (low <high && L->r[low] < L->r[0]) low++;
L->r[high] = L->r[low];
}
L->r[low] = L->r[0];
return low;
}
void QKSort(RecordList L, int low, int high)
{
int pos;
if (low < high)
{
pos = QKpass(L, low, high);
QKSort(L, low, pos - 1);
QKSort(L, pos + 1, high);
}
}
int main()
{
RecordList L;
printf(“请输入元素个数:\n”);
scanf("%d", &L.length);
for (int i = 1; i <= L.length; i++)
{
printf(“请输入第%d个元素的值:\n”,i);
scanf("%d",&L.r[i]);
}
QKSort(&L, 1, L.length);
for (int i = 1; i <= L.length; i++)
{
printf("%-4d", L.r[i]);
}
}