#include<stdio.h>
void sort(int a[],int low,int high)
{
int left = low;
int right = high;
int key = a[left];
if(left > right )
return ;
while(left < right)
{
//从右往左找比Key小的值
while(left < right && a[right] >= key)
{
right --;
}
a[left] = a[right];
//从左往右找比key大的值
while(left < right && a[left] <= key)
{
left ++;
}
a[right] = a[left];
}
a[left] = key;
sort(a,low,left - 1);//分治法
sort(a,left+1,high);//分治法
}
int main()
{
int i=0;
int vale[] = {1,2,3,9,7,6,8,4,5,0,10};
sort(vale,0,10);
for(i;i<11;i++)
{
printf("value[%d]=%d\t",i,vale[i]);
}
return 0;
}
运行结果