def isOdd(n): return n & 1 def Reorder(data, cf = isOdd): odd = 0 even = len( data ) - 1 while True: while not isOdd( data[ even ]) : even -= 1 while isOdd( data[ odd ]) : odd += 1 if odd >= even: break data[ even ], data[ odd ] = data[ odd ], data[ even ]
【剑指offer】Q14:调整数组顺序使奇数位于偶数前面,布布扣,bubuko.com
原文地址:http://blog.csdn.net/shiquxinkong/article/details/37321353