main.java
/*******************************************************************************************
     * SCOTT
     * Merge Sort in ascending and descending order.
     *******************************************************************************************/
SCOTT
Merge Sort in ascending and descending order.
SCOTT Merge Sort in ascending and descending order .
public static int[] merge(int arr[], int left, int mid, int right) {
        int sizeL=  mid - left + 1; 
        int sizeR = right - mid; 
        int leftArr[] = new int[sizeL];
        int rightArr[] = new int[sizeR];
        for (int i = 0; i < sizeL; ++i)
            leftArr[i] = arr[left + i];
        for (int j = 0; j < sizeR; ++j)
            rightArr[j] = arr[mid + 1 + j];
        int i = 0;
        int j = 0;
        int k = left;
        while (i < sizeL && j < sizeR) {
            if (leftArr[i] <= rightArr[j]) {
                arr[k] = leftArr[i];
                i++;
            }
            else {
                arr[k] = rightArr[j];
                j++;
            }
            k++;
        }
        while (i < sizeL) {
            arr[k] = leftArr[i];
            i++;
            k++;
        }
        while (i < sizeR) {
            arr[k] = rightArr[i];
            j++;
            k++;
        }
        return arr;
    }
public static int [ ] merge ( int arr [ ] , int left , int mid , int right ) { int sizeL = mid - left + 1 ; int sizeR = right - mid ; int leftArr [ ] = new int [ sizeL ] ; int rightArr [ ] = new int [ sizeR ] ; for ( int i = 0 ; i < sizeL ; ++ i ) leftArr [ i ] = arr [ left + i ] ; for ( int j = 0 ; j < sizeR ; ++ j ) rightArr [ j ] = arr [ mid + 1 + j ] ; int i = 0 ; int j = 0 ; int k = left ; while ( i < sizeL && j < sizeR ) { if ( leftArr [ i ] <= rightArr [ j ] ) { arr [ k ] = leftArr [ i ] ; i ++ ; } else { arr [ k ] = rightArr [ j ] ; j ++ ; } k ++ ; } while ( i < sizeL ) { arr [ k ] = leftArr [ i ] ; i ++ ; k ++ ; } while ( i < sizeR ) { arr [ k ] = rightArr [ i ] ; j ++ ; k ++ ; } return arr ; }
SCOTT
 Merge Sort in ascending and descending order.
SCOTT Merge Sort in ascending and descending order .
// size of left sub-array // size of right sub-array //temporary sub-arrays for left and right // Merging the 2 sub-arrays // see if there are remaining elements left in the sub-arrays to copy over