private static <E extends Comparable<E>> void merge(E[] array, int start, int middle, int end) {
        List<E> temp = new LinkedList<>();
        
        for(int i = 0; i < array.length; i++) {
            temp.add(array[i]);
        }
        
        int left = start;
        int right  = middle + 1;
        int current = start;
        

        while(left <= middle && right <= end) {
            if(temp.get(left).compareTo(temp.get(right)) <= 0) {
                array[current] = temp.get(left);
                left++;
            }
            else {
                array[current] = temp.get(right);
                right++;
            }
            
            current++;
        }
        
        while(left <= middle) {
            array[current] = temp.get(left);
            left++;
            current++;
        }
        

    }
private static < E extends Comparable < E > > void merge ( E [ ] array , int start , int middle , int end ) { List < E > temp = new LinkedList < > ( ) ; for ( int i = 0 ; i < array . length ; i ++ ) { temp . add ( array [ i ] ) ; } int left = start ; int right = middle + 1 ; int current = start ; while ( left <= middle && right <= end ) { if ( temp . get ( left ) . compareTo ( temp . get ( right ) ) <= 0 ) { array [ current ] = temp . get ( left ) ; left ++ ; } else { array [ current ] = temp . get ( right ) ; right ++ ; } current ++ ; } while ( left <= middle ) { array [ current ] = temp . get ( left ) ; left ++ ; current ++ ; } }
Merge two sorted arrays into a bigger array in ascending order. This routine runs in O(n) time.

@param <E> the type of elements in this array.

@param array array with two sorted sub arrays that will be merged
@param start index of the starting point of the left array
@param middle index that splits the array in two sub arrays
@param end index of the end point of the right array