#include "stdio.h"
void QuickSort(int *array, int low, int height)
{
int i, j, tmp; // 两个哨兵,和开头的元素下标
int temp;
i = low;
j = height;
tmp = array[low];
if (i > j) // 如果下标i大于下标j,函数结束运行
{
return;
}
while (i < j)
{
while (array[j] > array[i] && j>i)
{
j--;
}
while (array[i] <= tmp && j > i)
{
i++;
}
if (j > i)
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
array[low] = array[i];
array[i] = tmp;
// 左右两个子集
QuickSort(array, low, i - 1);
QuickSort(array, i + 1, height);
}
int main()
{
int count;
printf("数组的大小:");
scanf("%d", &count);
int array[count];
printf("\n输入数组元素:");
for (int i = 0; i < count; i++)
{
scanf("%d", &array[i]);
}
QuickSort(array, 0, count - 1);
printf("\n快速排序后:");
for (int i = 0; i < count; i++)
{
printf("%d ", array[i]);
}
return 0;
}
标签:02,count,int,QuickSort,快排,low,printf,array,排序
From: https://www.cnblogs.com/zhanjianhai/p/17741771.html