public class Test {
public static void main(String[] args) throws UnsupportedEncodingException {
int[] ints = { 1, 5, 10, 11 ,30, 13, 18, 22 ,55 };
int start = 0;
int end = ints.length - 1;
//快排
quickSort(ints, start, end);
System.out.println("==quickSort=="+Arrays.toString(ints));
}
public static void quickSort(int[] numbers,int low,int high){
if(low < high) {
int middle = getMiddle(numbers,low,high); //将numbers数组进行一分为二
quickSort(numbers, low, middle-1); //对低字段表进行递归排序
quickSort(numbers, middle+1, high); //对高字段表进行递归排序
}
}
public static int getMiddle(int[] numbers,int low,int high) {
int temp = numbers[low];
while(low<high)
{
while (low<high&&numbers[high]>=temp)//改写为<=可以实现从大到小排序
{
high--;
}
if(low<high)
{
numbers[low]=numbers[high];
}
while (low<high&&numbers[low]<=temp)//同上
{
low++;
}
if(high>low)
{
numbers[high]=numbers[low];
}
}
numbers[low] = temp;
return low;
}
}