package sort;
import utilities.containers.*;
/**
* This class subdivides a list of elements into a subsequences of elements,
* then merges the single elements in order to form a single ordered list.
*/
public class MergeSort <E>{
/**
* MergeSort Starting algorithm.
* Require: a non-empty list of elements to sort.
* Ensure: returns the input list in increasing order.
*
*/
public void mergesort(List <E> toSort){
if (toSort.size()<=1){
/*Do Nothing*/
}
else{
int low = 0;
int high = toSort.size()-1;
sort(toSort,low,high);
}
}
/**
* Private sort method used to break down input list into single list elements.
*
*/
private void sort(List <E> toSort,int low,int high){
if(low==high){
/*Do Nothing*/
}
else{
int middle = (high+low)/2;
sort(toSort,low,middle);
sort(toSort,middle,high);
merge(toSort,low, middle, high);
}
}
/**
* Private merge method used to merge and order two generic lists.
*/
private void merge(List<E> toSort,int low, int middle, int high){
/**
*This is the area I don't get.
*/
}
/**
* Swaps two generic elements of a list.
*/
private void swap(List<E> toSort,int left, int right){
E temp = toSort.get(left);
toSort.set(left,toSort.get(right));
toSort.set(right,temp);
}
}//end of class MergeSort