sort
Class generic_sort
java.lang.Object
|
+--sort.generic_sort
- Direct Known Subclasses:
- noise_filter.sort_by_index, noise_filter.sort_by_val, sortTest.sort_testElem_index, sortTest.sort_testElem_val
- public abstract class generic_sort
- extends java.lang.Object
A generic sort class for arrays whose elements are derived
from Object. Sadly, this does not include types like integer
and double.
This is an abstract class. The class that extends this class must
define the compare function. The compare function returns an
integer value that is less than, equal or greater than zero
depending on the result of the comparision (the function is modeled
after UNIX strcmp).
This class is based on the Java quicksort algorithm by
James Gosling at at Sun Microsystems (see below).
Method Summary |
protected abstract int |
compare(java.lang.Object a,
java.lang.Object b)
This is an abstract function that should be defined
by the class derived from generic_sort. |
private void |
QuickSort(java.lang.Object[] a,
int lo0,
int hi0)
This is a generic version of C.A.R Hoare's Quick Sort
algorithm. |
void |
sort(java.lang.Object[] a)
|
private void |
swap(java.lang.Object[] a,
int i,
int j)
Exchange element a[i] and a[j] |
Methods inherited from class java.lang.Object |
,
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
registerNatives,
toString,
wait,
wait,
wait |
generic_sort
public generic_sort()
swap
private void swap(java.lang.Object[] a,
int i,
int j)
- Exchange element a[i] and a[j]
QuickSort
private void QuickSort(java.lang.Object[] a,
int lo0,
int hi0)
- This is a generic version of C.A.R Hoare's Quick Sort
algorithm. This will handle arrays that are already
sorted, and arrays with duplicate keys.
If you think of a one dimensional array as going from
the lowest index on the left to the highest index on the right
then the parameters to this function are lowest index or
left and highest index or right. The first time you call
this function it will be with the parameters 0, a.length - 1.
- Parameters:
a
- an integer arraylo0
- left boundary of array partitionhi0
- right boundary of array partition
sort
public void sort(java.lang.Object[] a)
compare
protected abstract int compare(java.lang.Object a,
java.lang.Object b)
This is an abstract function that should be defined
by the class derived from generic_sort. This function
is passed two objects, a and b. It
compares them and should return the following values:
If (a == b) return 0
if (a < b) return -1
if (a > b) return 1