package com.example.demo.sort;
import java.util.Arrays;
/**
* @Author: wangsj
* @Date: 2021/7/20 13:51
*/
public class QuickSort {
public static void quickSort(int[] arr, int low, int high) {
if (low < high) {
int pivot = arr[low];
int p_pos = low;
int temp;
for (int i = low + 1; i <= high; i++) {
if (arr[i] > pivot) {
p_pos++;
temp = arr[p_pos];
arr[p_pos] = arr[i];
arr[i] = temp;
}
}
temp = arr[low];
arr[low] = arr[p_pos];
arr[p_pos] = temp;
quickSort(arr, low, p_pos -1);
quickSort(arr, p_pos + 1, high);
}
}
public static void main(String[] args) {
int[] arr = {12,39,87,15,89,15,48,76,14,98,12,74};
quickSort(arr, 0, arr.length -1);
System.out.println(Arrays.toString(arr));
}
}