Adjust the order of the arrays so that the odd digits are in the even front
Enter an array of integers to implement a function to adjust the order of the words 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.
Can be shipped with two pointers, the first pointer is initialized when it points to the first number of the array, it points back to move. The second pointer initializes with the last digit of the array, it moves forward only, and before two pointers meet, the first pointer is always in front of the second pointer.
(1) Moves backwards when the first pointer points to an odd number, and moves forward when the second pointer points to an even number;
(2) Conversely, the exchange of these two numbers;
#define _crt_secure_no_warnings 1
#include <stdio.h>
#include <assert.h
void Span style= "font-family: ' The new song Body '; Font-size:20px;background:rgb (255,255,255);" > reorderarray ( int * pdata int &NBSP; length
{
int *pstart= pdata ;
int *pend= pdata + length -1;
int temp;
assert ( pdata
if (*pdata= =NULL| | length ==0)
{
return ;
}
while (pstart<pend)
{
Move Pstart backwards until an even number is encountered
while(pstart<pend&& (*pstart&1)!=0)
{
pstart++;
}
Move forward pend until an odd number is encountered
while (pstart<pend&& (*pend&1) ==0)
{
pend--;
}
if (pstart<pend)
{
Temp=*pstart;
*pstart=*pend;
*pend=temp;
}
}
}
int Main ()
{
int arr[]={1,2,3,4,5,6,7,8,9,10};
int length= sizeof (arr)/ sizeof (Arr[0]);
int i=0;
Reorderarray (arr,length);
for (i=0;i<length;i++)
printf ("%d", Arr[i]);
System ("pause");
return 0;
}
Adjust the order of the arrays so that the odd digits are in the even front