Topic:
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.
Resolution: The topic did not say the relative position unchanged, with two cursors pointing to the head and tail, the front of the even and the back of the odd exchange can be.
/* Function function */void reorderoddeven (int a[], int length) {int i,j;//define two cursors int temp;if (a==null| | length==0) {printf ("Invalid Input"); return;} Cursors point to Array first i=0;j=length-1;while (I<J) {//To even while (i<j&& (a[i]&0x1)!=0) {i++;} Point to Odd while (i<j&& (a[j]&0x1) ==0) {j--;} Exchange Temp=a[i];a[i]=a[j];a[j]=temp;}}
Adjust the array order so that the odd digits are preceded by even numbers