/*****************************************
调整数组顺序使奇数位于偶数前面(可扩展性)
***************************************/
#include <iostream>
using namespace std;
bool Stard(int *x)//独立判断标准 可扩展
{
if (*x & 0x1)
{
return true;
}
return false;
}
int * ReorderArray(int *OriginArray, unsigned int length)
{
if (OriginArray == NULL || OriginArray[1] == NULL)
{
return OriginArray;
}
int *left = OriginArray;
int *right = OriginArray+length - 1;
int temp = 0;
while (left < right)
{
while (Stard(left))
{
left++;
}
while (!Stard(right))
{
right--;
}
temp = *right;
*right = *left;
*left = temp;
left++;
right--;
}
return OriginArray;
}
int main()
{
int OriginArray[] = {1,2,3,4,5,6,7,8,9};
int length = sizeof(OriginArray)/4;
ReorderArray(OriginArray, length);
for (int i = 0; i < length; i++)
{
cout<<OriginArray[i]<<" "<<endl;
}
return 0;
}