快速排序
思想:
代码:
public class QuickSort {
public static void quick(int[] a){
if(a.length > 0){
quickSort(a,0,a.length-1);
}
for(int b : a){
System.out.print(b+" ");
}
}
private static void quickSort(int[] a, int low, int high) {
if(low < high){
int mindle = sort(a,low,high);
quickSort(a,low,mindle-1);
quickSort(a,mindle+1 ,high);
}
}
private static int sort(int[] a, int low, int high) {
int temp = a[low];
while(low < high){
while(low < high && temp <= a[high])
high--;
a[low] = a[high];
while(low < high && temp >= a[low])
low++;
a[high] = a[low];
}
a[low] = temp;
return low;
}
public static void main(String[] args) {
int[] a = new int[]{19,3,5,7,89,54,78,96,52,15,55,6,4};
QuickSort.quick(a);
}
}
***帅气的远远啊***
来源:CSDN
作者:yuanyuan啊
链接:https://blog.csdn.net/qq_41585840/article/details/104074732