Java Reference
In-Depth Information
Example 2•9: Sorter.java (continued)
}
};
// Finally, sort the array of CollationKey objects, rearranging the
// original array of strings in exactly the same way.
sort(b, a, from, to, up, comp);
}
/** Sort an array of Comparable objects into ascending order */
public static void sort(Comparable[] a) {
sort(a, null, 0, a.length-1, true);
}
/**
* Sort a portion of an array of Comparable objects. If up is true,
* sort into ascending order, otherwise sort into descending order.
**/
public static void sort(Comparable[] a, int from, int to, boolean up) {
sort(a, null, from, to, up, comparable_comparer);
}
/**
* Sort a portion of array a of Comparable objects. If up is true,
* sort into ascending order, otherwise sort into descending order.
* Re-arrange the array b in exactly the same way as a.
**/
public static void sort(Comparable[] a, Object[] b,
int from, int to, boolean up) {
sort(a, b, from, to, up, comparable_comparer);
}
/**
* Sort an array of arbitrary objects into ascending order, using the
* comparison defined by the Comparer object c
**/
public static void sort(Object[] a, Comparer c) {
sort(a, null, 0, a.length-1, true, c);
}
/**
* Sort a portion of an array of objects, using the comparison defined by
* the Comparer object c. If up is true, sort into ascending order,
* otherwise sort into descending order.
**/
public static void sort(Object[] a, int from, int to, boolean up,
Comparer c)
{
sort(a, null, from, to, up, c);
}
/**
* This is the main sort() routine. It performs a quicksort on the elements
* of array a between the element from and the element to. The up argument
* specifies whether the elements should be sorted into ascending (true) or
* descending (false) order. The Comparer argument c is used to perform
* comparisons between elements of the array. The elements of the array b
* are reordered in exactly the same way as the elements of array a are.
**/
Search WWH ::




Custom Search