题目描述
输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变。
//从后往前找,遇到偶数移到末尾
public class Solution {
public void reOrderArray(int [] array) {
int temp=0;
int count=0;
for(int i=array.length-1;i>=0;i--)
{
if(array[i]%2==0)
{
for(int j=i;j<array.length-1-count;j++)
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
count++;
}
}
}
}