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

        while(left <= middle && right <= end) {
            list.remove(current);
            
            if(temp.get(left).compareTo(temp.get(right)) <= 0) {
                list.add(current, temp.get(left));
                left++;
            }
            else {
                list.add(current, temp.get(right));
                right++;
            }
            
            current++;
        }
        
        while(left <= middle) {
            list.remove(current);
            list.add(current, temp.get(left));
            left++;
            current++;
        }
        

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

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

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