PECS, and use Collections.reverseOrder().
There are actually 5 different implementations of quicksort in here when one will do (the array versions could go away and call the list version, wrapping in Arrays.asList()). But I won't touch those right now. I am super tempted to reduce things down to one List version and one array version. Also it's weird that there are customized Comparators that are null-safe. I believe I was the one who added them in the past, but I've since learned. It's a strange undocumented "convenience" when it's easy enough for someone to provide a null-safe comparator for comparables. (In guava you can call Ordering.natural().nullsLast()). git-svn-id: https://samskivert.googlecode.com/svn/trunk@2988 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
@@ -337,7 +338,7 @@ public class QuickSort
|
|||||||
* Sort the elements in the specified List according to the ordering imposed by the specified
|
* Sort the elements in the specified List according to the ordering imposed by the specified
|
||||||
* Comparator.
|
* Comparator.
|
||||||
*/
|
*/
|
||||||
public static <T> void sort (List<T> a, Comparator<T> comp)
|
public static <T> void sort (List<T> a, Comparator<? super T> comp)
|
||||||
{
|
{
|
||||||
sort(a, 0, a.size() - 1, comp);
|
sort(a, 0, a.size() - 1, comp);
|
||||||
}
|
}
|
||||||
@@ -365,20 +366,16 @@ public class QuickSort
|
|||||||
* Sort the elements in the specified List according to the reverse ordering imposed by the
|
* Sort the elements in the specified List according to the reverse ordering imposed by the
|
||||||
* specified Comparator.
|
* specified Comparator.
|
||||||
*/
|
*/
|
||||||
public static <T> void rsort (List<T> a, final Comparator<T> comp)
|
public static <T> void rsort (List<T> a, Comparator<? super T> comp)
|
||||||
{
|
{
|
||||||
sort(a, new Comparator<T>() {
|
sort(a, Collections.reverseOrder(comp));
|
||||||
public int compare (T o1, T o2) {
|
|
||||||
return comp.compare(o2, o1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort a subset of the elements in the specified List according to the ordering imposed by the
|
* Sort a subset of the elements in the specified List according to the ordering imposed by the
|
||||||
* specified Comparator.
|
* specified Comparator.
|
||||||
*/
|
*/
|
||||||
public static <T> void sort (List<T> a, int lo0, int hi0, Comparator<T> comp)
|
public static <T> void sort (List<T> a, int lo0, int hi0, Comparator<? super T> comp)
|
||||||
{
|
{
|
||||||
// bail out if we're already done
|
// bail out if we're already done
|
||||||
if (hi0 <= lo0) {
|
if (hi0 <= lo0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user