import java.util.Arrays;
public class quickSort {
public static void main(String[] args) {
int arr[]={9,8,7,6,5,4,3,2,1};
quick(arr,0,arr.length-1);
System.out.println(Arrays.toString(arr));
}
public static void quick(int[]arr,int low,int high){
int temp,i,j,t;
if(low>high){
return;
}
i = low;
j = high;
temp = arr[low];
while (i<j){
while(i<j&&arr[j]>=temp){
j--;
}
while(i<j&&arr[i]<=temp){
i++;
}
if(i<j){
t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
arr[low] = arr[i];
arr[i] = temp;
quick(arr,low,j-1);
quick(arr,j+1,high);
}
}
}
快速排序(排序5)
最新推荐文章于 2024-08-31 11:16:19 发布