快速排序

快速排序中在确定那个分割的中间量的时候需要注意几个循环的使用。

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);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值