import java.util.Scanner; public class QuickSort { public static void main(String[] args) { Scanner in = new Scanner(System.in); int count = in.nextInt(); int[] array = new int[count + 1]; for(int i = 0;i< count;i++) { array[i] = in.nextInt(); } quickSort(array,0,count - 1,count); for(int i = 0;i< count;i++) { System.out.print(array[i] + " "); } } private static void quickSort(int[] array ,int left,int right,int count) { int i = left; int j = right; if(left >= right) { return; } while( i < j) { while(array[i] < array[left] && i < count) { i ++; } while(array[j] > array[left]) { j --; } int temp = array[i]; array[i] = array[j]; array[j] = temp; } quickSort(array,left,j-1,count); quickSort(array,j + 1,right,count); } }
快速排序(java实现)
最新推荐文章于 2024-07-17 10:35:12 发布