Hier schau mal:
Java:
public static <T extends Comparable<? super T> > void sort(List<T> array) {
mergesort (array, 0, array.size() - 1, t);
}
private static <T extends Comparable<? super T>> void mergesort (List<T> a, int low, int high, int t) {
if (low < high) {
for (int i = 0; i < t; i++) {
mergesort (a,low + i*(high-low+1)/t, low + (i+1)*(high-low+1)/t - 1,t);
}
merge (a, low, high, t);
}
}
private static <T extends Comparable<? super T>> void merge (List<T> a, int low, int high, int t) {
List<T>[] lists = (List<T>[]) new List<?>[t];
for (int i = 0; i < t; i++) {
lists[i] = new ArrayList<T>();
for (int j=low + i*(high-low+1)/t; j<= low + (i+1)*(high-low+1)/t - 1; j++)
lists[i].add(a.get(j));
}
int[] size = new int[t];
int n = high - low;
for (int i = 0; i < t; i++) {
size[i] = low + (n/t)*i;
}
int resultindex=0;
T min =null;
int indexmin=0;
int index []=new int[t];
while(resultindex<high-low+1) {
min=null;
for(int i=0; i<t;i++) {
if(index[i] < lists[i].size()){
if(min==null || min.compareTo(lists[i].get(index[i]))>0) {
min=lists[i].get(index[i]);
indexmin=i;
}
}
}
index[indexmin]+=1;
a.set(resultindex,min);
resultindex++;
}
}