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, and all the even digits are in the second half of the array
C++:
1 voidReorderarray (vector<int> &Array) {2 intK =0 ;3 for(inti =0; I < array.size (); i++){4 if(Array[i]%2==1){5Swap (array[k++], array[i]);6 }7 }8}
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, and all the even digits are located in the second half of the array,
and ensure that the relative positions of the odd and odd, even and even are the same.
C++:
1 classSolution {2 Public:3 voidReorderarray (vector<int> &Array) {4 intOddnum =0 ;5 for(intA:array) {6 ifA2==1){7oddnum++ ;8 }9 }Ten inti =0 ; One intj =Oddnum; Avector<int> copy =Array; - for(intnum:copy) { - if(num%2==1){ thearray[i++] =num; -}Else{ -Array[j++] =num; - } + } - } +};
14 adjusting the array order so that the odd digits are preceded by even numbers