public static int[] mergeSort(int[] array)
    {
        if(array.length <= 1)
            return array;

        int middle = array.length/2;

        int[] left = new int[array.length-middle];
        int[] right = new int[array.length - left.length];

        for(int i = 0; i < left.length; i++)
            left[i] = array[i];
        for(int i = 0; i < right.length; i++)
            right[i] = array[middle + i];

        int[] sortedLeft = mergeSort(left);
        int[] sortedRight = mergeSort(right);

        return merge(sortedLeft, sortedRight);
    }