package test;
public class Quick2 {
public static void main(String[] args) {
int arr[] = {77,22,1,32,3};
quickSort(arr,0,arr.length-1);
for(int i = 0;i<arr.length;i++) {
System.out.println(arr[i]);
}
}
private static void quickSort(int[] arr, int low, int high) {
if(low>high) {
return;
}
int i = low ,j =high ,base = arr[low];
while(i<j) {
while(arr[j]>=base && i<j) {
j--;
}
while(arr[i]<=base && i<j) {
i++;
}
swap(arr,i,j);
}
swap(arr,low,j);
quickSort(arr, low, j-1);
quickSort(arr, j+1, high);
}
private static void swap(int[] brr, int k, int p) {
int temp = brr[k];
brr[k] = brr[p];
brr[p] = temp;
}
}
快速排序
最新推荐文章于 2024-06-20 23:50:49 发布