排序算法之挖坑填数法
作者:互联网
挖坑填数法+分治思想
import java.util.Arrays;
class Solution {
public static void main(String[] args) {
int[] arr={5,37,8,7,2};
quickSort_2(arr,0,4);
System.out.println(Arrays.toString(arr));
}
public static void quickSort_2(int[] data, int start, int end) {
if (data == null || start >= end) return;
int i = start, j = end;
int pivotKey = data[start];
while (i < j) {
while (i < j && data[j] >= pivotKey) j--;
if (i < j) data[i++] = data[j];
while (i < j && data[i] <= pivotKey) i++;
if (i < j) data[j--] = data[i];
}
data[i] = pivotKey;
quickSort_2(data, start, i - 1);
quickSort_2(data, i + 1, end);
}
}
标签:arr,end,填数法,start,int,挖坑,while,排序,data 来源: https://www.cnblogs.com/andrewlovemeimei/p/14492835.html