package com.hmx.algorithm;
/**
* @program: datastructureandalgorithm
* @description:
* @author: hmx
* @create: 2021-06-29 17:46
**/
public class QuickSort {
public static void quickSort(int[] arrays,int low,int high){
int divideIndex = getDivideIndex(arrays, low, high);
getDivideIndex(arrays,low,divideIndex - 1);
getDivideIndex(arrays,divideIndex + 1,high);
}
public static int getDivideIndex(int[] arrays,int low,int high){
int number = arrays[low];
while(low < high){
while(arrays[high] >= number && low < high) {
high--;
}
if(low < high){
arrays[low] = arrays[high];
}
while(arrays[low] <= number && low < high) {
low++;
}
if(low < high){
arrays[high] = arrays[low];
}
}
arrays[low] = number;
return low;
}
}
测试;
@Test
public void testQuickSort(){
int[] arrays = {49,38,65,97,76,13,27,49};
System.out.println("快速排序之挖坑排序前的数组:" + Arrays.toString(arrays));
QuickSort.quickSort(arrays, 0 , arrays.length - 1);
System.out.println("快速排序之挖坑排序后的数组:" +Arrays.toString(arrays));
}