@@ -0,0 +1,1302 @@
+%0Apublic class MergeSort %7B%0A%09%0A%09static public void main(String%5B%5D args) %7B%09%09%0A%09%09int%5B%5D unsorted = %7B10, 9, 8, 7, 6, 4, 5, 2, 3, 1%7D;%0A%09%09int%5B%5D sorted = mergeSort(unsorted);%0A%09%09%0A%09%09for (int i : sorted) %7B%0A%09%09%09System.out.println(i);%0A%09%09%7D%0A%09%7D%0A%09%0A%09static int%5B%5D mergeSort(int%5B%5D array) %7B%0A%09%09if (array.length == 1) %7B%0A%09%09%09return array;%0A%09%09%7D else %7B%0A%09%09%09int%5B%5D firstHalf = new int%5Barray.length / 2%5D;%0A%09%09%09System.arraycopy(array, 0, firstHalf, 0, array.length / 2);%0A%09%09%09firstHalf = mergeSort(firstHalf);%0A%09%09%09%0A%09%09%09int%5B%5D secondHalf = new int%5Barray.length - firstHalf.length%5D;%0A%09%09%09System.arraycopy(array, firstHalf.length, secondHalf, 0, array.length - firstHalf.length);%0A%09%09%09secondHalf = mergeSort(secondHalf);%0A%09%09%09%0A%09%09%09return merge(firstHalf, secondHalf);%0A%09%09%7D%0A%09%7D%0A%09%0A%09static int%5B%5D merge(int%5B%5D firstHalf, int%5B%5D secondHalf) %7B%0A%09%09int newLength = firstHalf.length + secondHalf.length;%0A%09%09int%5B%5D merged = new int%5BnewLength%5D;%0A%09%09%0A%09%09int j = 0;%0A%09%09int k = 0;%0A%09%09%0A%09%09for (int i = 0; i %3C merged.length; i++) %7B%0A%09%09%09if (j == firstHalf.length) %7B%0A%09%09%09%09merged%5Bi%5D = secondHalf%5Bk%5D;%0A%09%09%09%09k++;%0A%09%09%09%09continue;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09if (k == secondHalf.length) %7B%0A%09%09%09%09merged%5Bi%5D = firstHalf%5Bj%5D;%0A%09%09%09%09j++;%0A%09%09%09%09continue;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09if (firstHalf%5Bj%5D %3E secondHalf%5Bk%5D) %7B%0A%09%09%09%09merged%5Bi%5D = secondHalf%5Bk%5D;%0A%09%09%09%09k++;%0A%09%09%09%7D else %7B%0A%09%09%09%09merged%5Bi%5D = firstHalf%5Bj%5D;%0A%09%09%09%09j++;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09return merged;%0A%09%7D%0A%0A%7D%0A

Add MergeSort in Java