快速排序中在确定那个分割的中间量的时候需要注意几个循环的使用。
public static int partition(int []num,int low,int high){
int index=num[low];
while(low<high){
while(low<high&&num[high]>index)
{high--;}//此处右边大括号不可以放置在下面位置1处
if(low<high)
num[low]=num[high];//1
while(low<high&&index>num[low])
{low++;}//此处右边大括号不可以放置在下面位置2处
if(low<high)
num[high]=num[low];//2
}
num[low]=index;//重新赋值给num[0];
return low;//返回分割点
}
public static void quicksort(int num[],int low,int high)
{
if(low<high)
int mid=partition(num,low,high);
quicksort(num,low,mid-1);
quicksort(num,mid+1,high);
}
18万+

被折叠的 条评论
为什么被折叠?



