标签:creat [] oid author int end quick ++ ati util
import java.util.Arrays;
/**
* @author Created by on 18/4/20.
*/
public class QuickSort {
public static int partition(int[] array, int left, int right) {//没有设置第2个和第3个参数,这个最严重问题
int begin = left;
int end = right;
int pivot = array[left];
while(begin < end) {
while(begin < end && pivot <= array[end]) {
end--;
}
array[begin]= array[end];
array[end] = pivot;
while(begin < end && pivot > array[begin]) {//=漏
begin++;
}
array[end] = array[begin];
array[begin] = pivot;
}
return end;
}
public static void quicksort(int[] array, int i, int j) {
if (i >=j) {//没有判断返回,这是第二严重问题
return;
}
int result = partition(array, i, j);
quicksort(array,i,result-1);
quicksort(array,result+1,j);
}
public static void main(String[] args) {
int[] array= {49,38,65,97,76,13,27,49};
quicksort(array,0,7);
System.out.println(Arrays.toString(array));
}
}
标签:creat [] oid author int end quick ++ ati util
原文地址:https://www.cnblogs.com/godfatherback/p/8893217.html