classArray defquick_sort returnselfif length <= 1=> base = pop smaller, bigger = partition { |e| e < base } push base smaller.quick_sort + [base] + bigger.quick_sort end end
classMain{ publicstaticvoidmain(String[] a)throws Exception { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(r.readLine()); String tmp = r.readLine(); String[] str = tmp.split(" ");
ArrayList arr = new ArrayList<>(); for (int i = 0; i < n; i++) { arr.add(Integer.parseInt(str[i])); }
ArrayList result = quickSort(arr); printArrayList(result); }
privatestaticvoidprintArrayList(ArrayList result){ StringBuilder st = new StringBuilder(); for (int i = 0; i < result.size(); i++) { st.append(result.get(i)); if (i != result.size() - 1) { st.append(" "); } } System.out.println(st); }