package sorting;

import java.util.Comparator;

public class MergeSort {
    public static int[] mergeSort(int[] array, Comparator<Integer> comparator) {
	if(array.length == 0) {
	    return new int[]{};
	}

	return mergeSort(array, 0, array.length - 1, comparator);
    }

    private static int[] mergeSort(int[] array, int start, int end, Comparator<Integer> comparator) {
	if (start == end) {
	    return new int[]{array[start]};
	}

	int[] left = mergeSort(array, start, (start + end) / 2, comparator);
	int[] right = mergeSort(array, (start + end) / 2 + 1, end, comparator);
	int[] sorted = merge(left, right, comparator);
	
	return sorted;
    }

    public static int[] merge(int[] foo, int[] bar, Comparator<Integer> comparator) {
	int[] merged = new int[foo.length + bar.length];
	
	int fooIndex = 0, barIndex = 0, mergedIndex = 0;
	while (fooIndex < foo.length && barIndex < bar.length) {
	    if(comparator.compare(foo[fooIndex], bar[barIndex]) < 0) {
		merged[mergedIndex] = foo[fooIndex];
		fooIndex++;
	    } else {
		merged[mergedIndex] = bar[barIndex];
		barIndex++;
	    }
	     
	    mergedIndex++;
	}

	while (fooIndex < foo.length) {
	    merged[mergedIndex++] = foo[fooIndex++];
	}

	while (barIndex < bar.length) {
	    merged[mergedIndex++] = bar[barIndex++];
	}
	
	return merged;
    }    
}

@@ -202,22 +202,30 @@
 %7D;%0A%09%7D%0A%0A%09
-return
+int%5B%5D sorted =
  mergeSo
@@ -268,16 +268,125 @@
 rator);%0A
+%09for (int index = 0; index %3C array.length; index++) %7B%0A%09    array%5Bindex%5D = sorted%5Bindex%5D;%0A%09%7D%0A%0A%09return sorted;%0A
     %7D%0A%0A 

Modify return type of mergeSort(...) method.