#include<stdio.h>
int main()
{
int QuikSort(int array[],int low,int high);
int array[10] = {2,5,8,1,7,5,11,9,37,6};
QuikSort(array,0,sizeof(array)/sizeof(int));
for(int i = 0;i < 10;i++)
{
printf("%d ",array[i]);
}
return 0;
}
int QuikSort(int array[],int low,int high)
{
int i = low;
int high_2 = high;
int low_2 = low;
int temp;
if(low < high)
{
for(;low < high;)
{
if(array[i] >= array[high])
{
temp = array[i];
array[i] = array[high];
array[high] =temp;
i = high;
low ++;
//low和high的作用分别代表比枢轴值小/大的元素的边界
}
if(array[i] <= array[low])
{
temp = array[i];
array[i] = array[low];
array[low] =temp;
i = low;
high --;
}
}
QuikSort(array,low_2,i-1);
//递归求解子问题
QuikSort(array,i+1,high_2);
}
else
{
return 0;
}
}
转载:https://blog.csdn.net/hnujunjie/article/details/100541673
查看评论