类似荷兰国旗问题
JAVA 代码
class Solution {
public static void reOrderArray(int [] array) {
int left = -1;
for (int i = 0; i < array.length; i++) {
if (isOdd(array[i])){
//先保存奇数,然后将奇数到left中间的偶数全部后移
int temp = array[i];
//将偶数全部后移
for (int j = i - 1; j > left; j--){
array[j + 1] = array[j];
}
//放置奇数
array[left + 1] = temp;
left++;
}
}
}
public static boolean isOdd(int num){
return num % 2 == 1;
}
}