void
Qsort(
int
arr[],
int
low,
int
high){
if
(high <= low)
return
;
int
i = low;
int
j = high + 1;
int
key = arr[low];//把第一个当作分界值
while
(
true
)
{
/*从左向右找比key大的值*/
while
(arr[++i] < key)
{
if
(i == high){
break
;
}
}
/*从右向左找比key小的值*/
while
(arr[--j] > key)
{
if
(j == low){
break
;
}
}
if
(i >= j)
break
;//左边都比边界小,右边都比边界大,则结束此次分界
/*交换i,j对应的值*/
int
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
/*中枢值与j对应值交换*/
int
temp = arr[low];
arr[low] = arr[j];
arr[j] = temp;
Qsort(arr, low, j - 1);
Qsort(arr, j + 1, high);
}