标签:else swap more 排序 static quicksort turn stat ati
package com.cisco.www.sort;
public class QuickSort {
public static void quickSort(int[] arr,int L,int R){
int[] p = partition(arr,L,R);
quickSort(arr,L,p[0]-1);
quickSort(arr,p[1]+1,R);
}
public static int[] partition(int[] arr,int L,int R){
int less = L -1;
int more = R+1;
int cur= L;
while (cur<more){
if(arr[cur]<arr[R]){
swap(arr,++less,cur++);
}else if(arr[cur]>arr[R]){
swap(arr,--more,L);
}else {
cur++;
}
}
swap(arr,more,R);
return new int[]{less+1,more};
}
private static void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
标签:else swap more 排序 static quicksort turn stat ati
原文地址:https://www.cnblogs.com/bigdata-stone/p/11042340.html