自己版:
package leetcode.mySort;
public class QuickSort {
public static int partition(int[] array,int start,int end){
int base = array[start];
while (start < end){
while (start < end && array[end]>base){
end--;
}
array[start] = array[end];
while (start <end && array[start]<base){
start++;
}
array[end] = array[start];
}
array[end] = base;
return start;
}
public static void quickSort(int[] array,int start,int end){
if (start < end){
int index = partition(array,start,end);
quickSort(array,start,index-1);
quickSort(array,index+1,end);
}
}
public static void main(String[] args) {
int[] array = {2,4,6,1,3,5};
quickSort(array,0,array.length-1);
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
}
}
优化参考:https://juejin.cn/post/7109087643660451877#comment
标签:end,int,start,while,array,排序,快速,public From: https://www.cnblogs.com/chenyi502/p/16817153.html