import java.io.*; class UseLists5 // Uses ArrayList rather than List { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str; ArrayList l1, l2; System.out.println("Enter a list: "); str = in.readLine(); l1 = ArrayList.fromString(str); l2 = quickSort(l1); System.out.println("Sorting the list gives: "); System.out.println(l2); } public static ArrayList quickSort(ArrayList l) { return quickSort(l,ArrayList.empty()); } private static ArrayList quickSort(ArrayList l,ArrayList acc) { while(!l.isEmpty()) { int p = l.head(); ArrayList s = ArrayList.empty(); ArrayList g = ArrayList.empty(); for(l=l.tail();!l.isEmpty();l=l.tail()) { int h = l.head(); if(h>p) g=g.cons(h); else s=s.cons(h); } acc = quickSort(g,acc).cons(p); l = s; } return acc; } }