All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----com.sgi.sysadm.util.Sort
Most methods operate on a range of elements. A range is described
by the index of its first element and an index that is
one past its last element. So, for example,
[n, n+1) is a range that contains one element,
[n, n) is a range that contains zero elements,
and [n, n-1) is not a valid range.
Unless otherwise specified, the test for equality uses
the == operator by default. Any different notion of
equality may be represented as a BinaryPredicate. You can use the
predefined class Equals, which implements BinaryPredicate, if you want
to use the Object.equals() method.
array[middle] is put in
array[first], array[middle+1] is put in
array[first+1], etc.
public Sort()
public static void stable_sort(Object array[],
int first,
int last,
BinaryPredicate comp)
N (log N)^2.
public static void insertion_sort(Object array[],
int first,
int last,
BinaryPredicate comp)
public static void inplace_merge(Object array[],
int first,
int middle,
int last,
BinaryPredicate comp)
[first, middle)
and [middle, last), and the resulting range is
[first, last).
Elements in the first input range will precede equal elements in the
second.
Sorting is by a user-supplied comparison function.
public static int lower_bound(Object array[],
int first,
int last,
Object x,
BinaryPredicate comp)
[first, i),
comp.apply(array[j], x) is
true.
public static int upper_bound(Object array[],
int first,
int last,
Object x,
BinaryPredicate comp)
[first, i),
comp.apply(x, array[j]) is
false.
public static void reverse(Object array[],
int first,
int last)
public static void rotate(Object array[],
int first,
int middle,
int last)
array[middle] is put in
array[first], array[middle+1] is put in
array[first+1], etc. Generally, the element in position
i is put into position
(i + (last-middle)) % (last-first).
array[first]
All Packages Class Hierarchy This Package Previous Next Index