#NEWLINE# def merge_sort( a , cmp ) : #NEWLINE# #INDENT# if ( len ( a ) < 2 ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# mid = ( len ( a ) // 2 ) #NEWLINE# lefthalf = a [ : mid ] #NEWLINE# righthalf = a [ mid : ] #NEWLINE# merge_sort ( lefthalf , cmp ) #NEWLINE# merge_sort ( righthalf , k ) #NEWLINE# i = 0 #NEWLINE# j = 0 #NEWLINE# k = 0 #NEWLINE# while ( ( i < len ( lefthalf ) ) and ( j < len ( righthalf ) ) ) : #NEWLINE# #INDENT# if ( cmp ( lefthalf [ i ] , righthalf [ j ] ) <= 0 ) : #NEWLINE# #INDENT# a [ k ] = lefthalf [ i ] #NEWLINE# i = ( i + 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# a [ k ] = righthalf [ j ] #NEWLINE# j = ( j + 1 ) #NEWLINE# #UNINDENT# k = ( k + 1 ) #NEWLINE# #UNINDENT# while ( i < len ( lefthalf ) ) : #NEWLINE# #INDENT# a [ k ] = lefthalf [ i ] #NEWLINE# i = ( i + 1 ) #NEWLINE# k = ( k + 1 ) #NEWLINE# #UNINDENT# while ( j < len ( righthalf ) ) : #NEWLINE# #INDENT# a [ k ] = righthalf [ j ] #NEWLINE# j = ( j + 1 ) #NEWLINE# k = ( k + 1 )