The title description enters an array of integers, implements a function to adjust the order of the numbers in the array, so that all the odd digits are placed in the first half of the array, all the even digits are located in the second half of the array, and the relative positions between the odd and odd, even and even are guaranteed.
classSolution { Public: voidReorderarray (vector<int> &Array) { intOdd=0; inteven=0; intn=array.size (); if(n==0&&n==1) return; while(odd<n&&even<N) { while(odd<n&& (array[odd]&1)==1)) Odd++; if(odd<N) {even=odd+1; while(even<n&& (array[even]&1)==0)) Even++; if(even<N) {inttemp=Array[even]; for(inti=even;i>odd;i--) Array[i]=array[i-1]; Array[odd]=temp; Odd++; } } } }};
One problem to note: the assignment operator "= =" has a higher priority than "&" because the operator priority problem is looking for a bug for a long time tat ...
Adjust the array order so that the odd digits are preceded by even numbers