Merging the subarrays using shell sorting Time Complexity : O ( nlog n ) Space Complexity : O ( 1 )
function inPlaceMerge ( nums , start , end ) { let gap = end - start + 1 ; for ( gap = nextGap ( gap ) ; gap > 0 ; gap = nextGap ( gap ) ) { for ( let i = start ; i + gap <= end ; i ++ ) { let j = i + gap ; if ( nums [ i ] > nums [ j ] ) swap ( nums , i , j ) ; } } }