|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectMergeSort
public class MergeSort
Constructor Summary | |
---|---|
MergeSort()
|
Method Summary | ||
---|---|---|
static
|
merge(java.util.Vector<T> theVector,
java.util.Vector<T> tempVector,
int first,
int mid,
int last)
This method is called to merge two portions of theVector that are already in
sorted order. |
|
static
|
mergesort(java.util.Vector<T> theVector,
java.util.Vector<T> tempVector,
int first,
int last)
This is the recursive method that does the merge sort of theVector , which
has Objects of type T . |
|
static
|
sort(java.util.Vector<T> theVector)
This is the method that users will call to sort the specified Vector of Objects of type T . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MergeSort()
Method Detail |
---|
public static <T extends java.lang.Comparable<? super T>> void sort(java.util.Vector<T> theVector)
This is the method that users will call to sort the specified Vector of
Objects of type T
.
This method creates a tempVector
and initializes it to contain
theVector.size() null
elements.
This method will call the mergesort
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.public static <T extends java.lang.Comparable<? super T>> void mergesort(java.util.Vector<T> theVector, java.util.Vector<T> tempVector, int first, int last)
theVector
, which
has Objects of type T
.
Either T
or a superclass of T
must implement
the Comparable
interface.
theVector
- The Vector of Objects of type T
to be sorted.tempVector
- The temporary 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 Vectorpublic static <T extends java.lang.Comparable<? super T>> void merge(java.util.Vector<T> theVector, java.util.Vector<T> tempVector, int first, int mid, int last)
This method is called to merge two portions of theVector
that are already in
sorted order. The indices of these portions are specified by first
,
mid
and last
. All the elements of theVector
are Objects
of type T
.
Either T
or a superclass of T
must implement
the Comparable
interface.
The merge operation first merges all the elements in proper sorted order from the two portions
of theVector
into tempVector
. When the merge is complete, all the
elements are then copied back into theVector
.
theVector
- The Vector of Objects of type T
to be sorted.tempVector
- The temporary Vector of Objects of type T
to be sorted.first
- The index of the beginning of the first section of theVector
to be merged.mid
- The index of the end of the first section of theVector
to be merged.last
- The index of the end of the second section of theVector
to be merged.
Please note that the index of the beginning of the second section of theVector
to be merged is at index = mid + 1
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |