public static void main(String[] args) {
int[] a = {1,58,25,26,11,10,30,19,27};
quickSort(a, 0, a.length - 1);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
public static int partition(int[] arr ,int left ,int right){
int point = arr[left];
int temp;
while(left < right){
while(left < right && arr[right]>=point)
--right;
temp=arr[left];
arr[left]=arr[right];
arr[right]=temp;
while(left < right && arr[left] <= point)
++left;
temp=arr[left];
arr[left]=arr[right];
arr[right]=temp;
}
arr[left]=point;
return left;
}
public static void quickSort(int[] arr ,int left ,int right){
if(left <right ){
int position = partition(arr,left,right);
quickSort(arr,left,position-1);
quickSort(arr,position+1,right);
}
}
java 快速排序
最新推荐文章于 2024-07-17 10:35:12 发布