Merging the subarrays using shell sorting Time Complexity : O ( nlog n ) Space Complexity : O ( 1 )
def inPlaceMerge ( nums , start , end ) : NEW_LINE INDENT gap = end - start + 1 NEW_LINE gap = nextGap ( gap ) NEW_LINE while gap > 0 : NEW_LINE INDENT i = start NEW_LINE while ( i + gap ) <= end : NEW_LINE INDENT j = i + gap NEW_LINE if nums [ i ] > nums [ j ] : NEW_LINE INDENT swap ( nums , i , j ) NEW_LINE DEDENT i += 1 NEW_LINE DEDENT gap = nextGap ( gap ) NEW_LINE DEDENT DEDENT