package cn; import java.util.Arrays; public class Test46 { public static void main(String[] args) { int [] arr = {42,52,7,99,63,25,56,78,49}; System.out.println(Arrays.toString(arr)); quickSort(arr,0,arr.length-1); System.out.println(Arrays.toString(arr)); } public static void quickSort(int[] nums,int low,int high){ if(low < high){ int index = partition(nums,low,high); partition(nums,low,index-1); partition(nums,index+1,high); } } public static int partition(int[] nums,int low,int high){ int i = low; int j = high; int x = nums[low]; while(i<j){ while(nums[j] >= x && i<j){ j--; } if(i<j){ nums[i] = nums[j]; i++; } while(nums[i] <= x && i<j){ i++; } if(i<j){ nums[j] = nums[i]; j--; } } nums[i] = x; return i; } }
快速排序
最新推荐文章于 2021-11-19 16:57:43 发布