An funy question!
Q: An int array, devide an array of integers into two parts, odd in the first part, and even in the second part.
We need some sub Function:
1: IsEven(int n) // n is Even or not
2: void Reorder(int *pData, unsigned int length, bool (*func)(int));
void Reorder(int *pData, unsigned int length, bool (*func)(int))
{
if (Null==pData || length==0)
return;
//
int *Pbegin = pData;
int *Pend = pdata+length-1;
//
while(Pbegin<Pend)
{
if(!func(*Pbegin))
{
Pbegin++;
continue;
}
//
if(func(*Pend))
{
Pend--;
continue;
}
//Swap
int temp;
temp = * Pbegin;
*Pbegin = *Pend;
*Pend = temp;
}
}
bool IsEven(int n)
{
return(n&1)==0;
}
void ReorderOddEven(int *pData, unsigned int length)
{
Reorder(pData, length, isEven);
}