Class MergeSort

java.lang.Object
  extended by MergeSort

public class MergeSort
extends java.lang.Object


Constructor Summary
MergeSort()
           
 
Method Summary
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.
static
<T extends java.lang.Comparable<? super T>>
void
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
<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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MergeSort

public MergeSort()
Method Detail

sort

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.

Parameters:
theVector - The Vector of Objects of type T to be sorted.

mergesort

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)
This is the recursive method that does the merge sort of theVector, which has Objects of type T.

Either T or a superclass of T must implement the Comparable interface.

Parameters:
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 Vector
last - Index of the last entry of the Vector

merge

public 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.

Parameters:
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