1 void ReorderOddEven(int *pData , unsigned int length) 2 { 3 if (!pData || length <= 0) 4 { 5 return; 6 } 7 int* pBegin = pData ; 8 int* pEnd = pData + length - 1 ; 9 while (pBegin < pEnd) 10 { 11 while( pBegin<pEnd && (((*pBegin) & 0x1) == 1) )//找到偶数位置 12 { 13 pBegin++; 14 } 15 while( pBegin<pEnd && ( ((*pEnd) & 0x1) != 1) )//找到寄数位置 16 { 17 pEnd--; 18 } 19 if (pBegin<pEnd) 20 { 21 int temp = *pBegin ; 22 *pBegin = *pEnd ; 23 *pEnd = temp ; 24 } 25 }