<s> def merge ( a , b , cmp , next ) : <EOL> if a is None : <EOL> head = b <EOL> elif b is None : <EOL> head = a <EOL> else : <EOL> if cmp ( a , b ) <= <NUM_LIT:0> : <EOL> ptr = a <EOL> a = getattr ( a , next ) <EOL> else : <EOL> ptr = b <EOL> b = getattr ( b , next ) <EOL> head = ptr <EOL> while a and b : <EOL> if cmp ( a , b ) <= <NUM_LIT:0> : <EOL> setattr ( ptr , next , a ) <EOL> ptr = a <EOL> a = getattr ( a , next ) <EOL> else : <EOL> setattr ( ptr , next , b ) <EOL> ptr = b <EOL> b = getattr ( b , next ) <EOL> if a : <EOL> setattr ( ptr , next , a ) <EOL> else : <EOL> setattr ( ptr , next , b ) <EOL> return head <EOL> LISTSIZE = <NUM_LIT:30> <EOL> def msort ( list , next , cmp ) : <EOL> set = [ None ] * LISTSIZE <EOL> while list : <EOL> ep = list <EOL> list = getattr ( list , next ) <EOL> setattr ( ep , next , None ) <EOL> i = <NUM_LIT:0> <EOL> while i < LISTSIZE - <NUM_LIT:1> and set [ i ] : <EOL> ep = merge ( ep , set [ i ] , cmp , next ) <EOL> set [ i ] = None <EOL> i += <NUM_LIT:1> <EOL> set [ i ] = ep <EOL> ep = None <EOL> for i in range ( LISTSIZE ) : <EOL> if set [ i ] : <EOL> ep = merge ( set [ i ] , ep , cmp , next ) <EOL> return ep </s>
