首页 > 代码库 > 【剑指offer】Q14:调整数组顺序使奇数位于偶数前面

【剑指offer】Q14:调整数组顺序使奇数位于偶数前面

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 ]