快速排序
import java.util.HashMap;
public class demo {
public static void main(String[] args) {
int[] arr = { 49, 38, 65, 97, 23, 22, 76, 1, 5, 8, 2, 0, -1, 22 };
quicksort(arr, 0, arr.length - 1);
System.out.println("排序后:");
for (int i : arr) {
System.out.println(i);
}
}
public static void quicksort(int[] arr,int low,int high) {
if(low<high){
int index = getIndex(arr,low,high);
quicksort(arr,low,index-1);
quicksort(arr,index+1,high);
}
}
public static int getIndex(int[] arr,int low,int high) {
int temp = arr[low];
while (low < high) {
while (low < high && arr[high] >= temp) {
high--;
}
arr[low] = arr[high];
while (low < high && arr[low] < temp) {
low++;
}
arr[high] = arr[low];
}
arr[low]= temp;
return low;
}
}