Take an array of integers and implement a function to adjust the order of the numbers in the array so that all odd numbers are in the first half of the array and all even numbers are in the second half of the array, and the relative positions between odd and odd numbers and even and even numbers remain the same. // Calculate the number of odd numbers. Open a new data, one pointer starting at 0 and one pointer starting at an odd number of positions.

import java.util.Arrays;
public class Solution {
    public void reOrderArray(int [] array) {
        int count=0;
        for(int i=0; i<array.length; i++){if(array[i]%2==1){
                ++count;
            }
        }
        int[] bak=Arrays.copyOf(array,array.length);
        int i=0,j=count;
        for(int val:bak){
            if(val%2==0)
               array[j++]=val;
            elsearray[i++]=val; }}}Copy the code