1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| import java.io.*; import java.lang.*; Class Main{ public static void quickSort(int[] arr, int left, int right){ if(left >= right){ return; } int middle = arr[left + (right - left)/2]; int l = left - 1; int r = right + 1; while(l < r){ do{ l++; }while(arr[l] < middle); do{ r--; }while(arr[r] > middle); if(l < r){ int tmp = arr[l]; arr[l] = arr[r]; arr[r] = tmp; } } quickSort(arr, left ,r); quickSort(arr, r+1, right); } public static void main(String[] args){ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); try{ String n = bf.readLine(); String str = bf.readLine(); int[] arr = new int[Integer.valueOf(n)]; String[] arrStr = str.split(" "); for(int i = 0; i < arrStr.length; i++){ arr[i] = Integer.valueOf(arrStr[i]); }
quickSort(arr, 0, arr.length - 1);
for(int i = 0; i < arr.length; i++){ System.out.print(arr[i]); if(i != arr.length -1){ System.out.print(" "); } } }catch(Exception e){ System.out.println(e); } } }
|