Enter an array of integers to implement a function to adjust the order of the numbers in the array, so that all the odd digits are in the first half of the array, all the even digits are in the second half of the array, and the relative positions of the odd and odd, even and even are constant.
/** idea: Using bubble sort 22 All adjacent numbers can be traversed to compare the first and subsequent numbers * When a number is even if the number of even digits behind him is the same, the relative position is unchanged, * and if he is odd, the relative position needs to be changed*/functionReorderarray (array) {if(array.length==0){ return []; } for(vari=0;i<array.length;i++){ for(varj=1;j<array.length;j++){ if(Array[j]%2==0 && array[j+1]%2!=0){ vartemp=Array[j]; ARRAY[J]=array[j+1]; Array[j+1]=temp; } } } returnArray;}
Adjust the array order so that the odd digits are preceded by even numbers