|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object QuickSort
public class QuickSort
Nested Class Summary | |
---|---|
static class |
QuickSort.PivotType
This enum specifies the pivot type that QuickSort will use. |
Constructor Summary | |
---|---|
QuickSort()
|
Method Summary | ||
---|---|---|
static
|
choosePivot(java.util.Vector<T> theVector,
int first,
int last,
QuickSort.PivotType pivotType)
This method selects the pivot according to the type of pivot specified. |
|
static
|
partition(java.util.Vector<T> theVector,
int first,
int last,
QuickSort.PivotType pivotType)
This method first finds the pivot p by calling choosePivot and
then partitions and rearranges the elements of the Vector in the following manner:
|
|
static
|
quickSort(java.util.Vector<T> theVector,
int first,
int last,
QuickSort.PivotType pivotType)
This is the recursive method that implements the QuickSort algorithm. |
|
static
|
sort(java.util.Vector<T> theVector,
QuickSort.PivotType pivotType)
This is the method that users will call to sort the specified Vector of Objects of type T using QuickSort. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public QuickSort()
Method Detail |
---|
public static <T extends java.lang.Comparable<? super T>> void sort(java.util.Vector<T> theVector, QuickSort.PivotType pivotType)
This is the method that users will call to sort the specified Vector of
Objects of type T
using QuickSort. The method of choosing the pivot
is
also specified by the user.
This method will call the quickSort
method to perform the recursive sort.
The Comparable
interface must either be implemented by T
or a superclass of T
.
When this method is done, the specified Vector is sorted.
theVector
- The Vector of Objects of type T
to be sorted.pivotType
- The method of choosing the pivot
during the QuickSort.public static <T extends java.lang.Comparable<? super T>> void quickSort(java.util.Vector<T> theVector, int first, int last, QuickSort.PivotType pivotType)
theVector
- The Vector of Objects of type T
to be sorted.first
- Index of the first entry of the Vectorlast
- Index of the last entry of the VectorpivotType
- The method of choosing the pivot
during the QuickSort.public static <T extends java.lang.Comparable<? super T>> void choosePivot(java.util.Vector<T> theVector, int first, int last, QuickSort.PivotType pivotType)
This method selects the pivot
according to the type of pivot specified.
The chosen pivot
will end up as the first
element in the
specified Vector.
theVector
- The Vector of Objects of type T
to be sorted.first
- Index of the first entry of the Vectorlast
- Index of the last entry of the VectorpivotType
- The method of choosing the pivot
during the QuickSort.public static <T extends java.lang.Comparable<? super T>> int partition(java.util.Vector<T> theVector, int first, int last, QuickSort.PivotType pivotType)
p
by calling choosePivot
and
then partitions and rearranges the elements of the Vector in the following manner:
{ [ elements < p ] p [ elements >= p] }.
theVector
- The Vector of Objects of type T
to be sorted.first
- Index of the first entry of the Vectorlast
- Index of the last entry of the VectorpivotType
- The method of choosing the pivot
during the QuickSort.
p
after the partition.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |