while(low<high && k[high] >=point) //过滤掉尾部大于基准点的值,不需要交换
{
high--;
}
k[low] = k[high]; //基准点多次交换为无谓交换直接赋值即可
while(low<high && k[low] <=point) //过滤掉头部小于基准点的值,不需要交换
{
low++;
}
k[high] = k[low]; //基准点多次交换为无谓交换直接赋值即可
}
k[low] = point;
return low;
}
int q_sort(int *k,int low,int high)
{
int point;
if(low<high)
{
point = partition(k,low,high);
q_sort(k,low,point-1); //实现递归前半部分
q_sort(k,point+1,high); //实现递归后半部分
}
return 0;
}
int main()
{
int i,a[10]={13,3,2,9,34,5,102,90,20,2}; //测试数据
q_sort(a,0,9); //数组下标0 9
printf("sort result:");
for(i=0;i<10;i++)
{
printf("%d ",a[i]);
}
printf("\n");
}