implement Arrays.sort

This commit is contained in:
Joel Dice 2007-12-03 16:32:54 -07:00
parent 266c256116
commit 9f5c2f4122

View File

@ -11,6 +11,19 @@ public class Arrays {
return (a == null && b == null) || (a != null && a.equals(b));
}
public static <T> void sort(T[] array, Comparator<? super T> comparator) {
// insertion sort
for (int j = 1; j < array.length; ++j) {
T t = array[j];
int i = j - 1;
while (i >= 0 && comparator.compare(array[i], t) > 0) {
array[i + 1] = array[i];
i = i - 1;
}
array[i + 1] = t;
}
}
public static <T> List<T> asList(final T ... array) {
return new List<T>() {
public String toString() {