package com.mergesort;

public class Sort {

    public int[] sortArray(int[] array) {

        int[] x = null;
        int[] y = null;

        if (array.length > 1) {

            int middleIndex = array.length / 2;
            x = sortArray(copyArray(array, 0, middleIndex));
            y = sortArray(copyArray(array, middleIndex + 1, array.length - 1));
        }
        return mergeSort(x, y);
    }

    public int[] copyArray(int[] array, int low, int high) {

        int[] newArray = null;
        for (int i = low; i < high; i++) {
            newArray[i] = array[i];
        }

        return newArray;
    }

    public int[] mergeSort(int[] a, int[] b) {
        int[] result = null;
        int resultLength = a.length + b.length;
        int k = 0,m = 0; //   

        for (int i = 0; i < resultLength; i++) {
            if (k <= a.length && m <= b.length) {
                if (a[k] < b[m]) {
                    result[i] = a[k];
                    k++;
                } else {
                    result[i] = b[m];
                    m++;
                }
            } else if (k <= a.length) {
                result[i] = a[k];
                k++;
            } else {
                result[i] = b[m];
                m++;
            }
        }

        return result;
    }

}
@@ -49,21 +49,20 @@
  public 
-int%5B%5D
+void
  sortArr
@@ -83,58 +83,8 @@
 ) %7B%0A
-%0A        int%5B%5D x = null;%0A        int%5B%5D y = null;%0A%0A
     
@@ -107,25 +107,24 @@
 ngth %3E 1) %7B%0A
-%0A
             
@@ -175,21 +175,17 @@
     
-x = sortArray
+mergeSort
 (cop
@@ -213,18 +213,17 @@
 leIndex)
-);
+,
 %0A       
@@ -231,22 +231,16 @@
     
-y = sortArray(
+        
 copy
@@ -303,40 +303,8 @@
   %7D%0A
-        return mergeSort(x, y);%0A
     
@@ -367,17 +367,16 @@
 high) %7B%0A
-%0A
         
@@ -479,33 +479,32 @@
 y%5Bi%5D;%0A        %7D%0A
-%0A
         return n
@@ -1169,25 +1169,24 @@
 %7D%0A        %7D%0A
-%0A
         retu
@@ -1202,10 +1202,9 @@
 ;%0A    %7D%0A
-%0A
 %7D

fix method sortArray