Sorting algorithms/Quicksort: Difference between revisions
Content deleted Content added
→{{header|Java}}: Now works with all Comparable types |
|||
Line 233: | Line 233: | ||
{{trans|Python}} |
{{trans|Python}} |
||
<java>public static LinkedList< |
<java>public static <E extends Comparable<E>> LinkedList<E> quickSort(LinkedList<E> arr){ |
||
LinkedList< |
LinkedList<E> less= new LinkedList<E>(); |
||
LinkedList< |
LinkedList<E> pivotList= new LinkedList<E>(); |
||
LinkedList< |
LinkedList<E> more= new LinkedList<E>(); |
||
if(arr.size() <= 1) return arr; |
if(arr.size() <= 1) return arr; |
||
E pivot= arr.getFirst(); //This pivot can change to get faster results |
|||
for( |
for(E i: arr){ |
||
if(i |
if(i.compareTo(pivot)<0) |
||
less.add(i); |
less.add(i); |
||
else if(i |
else if(i.compareTo(pivot)>0) |
||
more.add(i); |
more.add(i); |
||
else |
else |