// jishu_before_oushu.cpp :
//
#include "stdafx.h"
#if 0
void fun(int* a, int len)
{
int head = 0;
int tail = len - 1;
for (int j = 0;j<len/2;j++)
{
for(int i = 0; i<len; i++)
{
if ( (a[i] & 0x1) == 0 )
{
head = i;
break;
}
}
for(int i = len -1 ; i >= 0; i--)
{
if ( (a[i] & 0x1) == 1 )
{
tail = i;
break;
}
}
int temp = a[head];
a[head] = a[tail];
a[tail] = temp;
}
}
#else
void fun(int* a, int len)
{
int head = 0;
int tail = len - 1;
while(head < tail)
{
while ( (a[head] & 0x1) == 1 && (head < tail) )
{
head++;
}
while ( (a[tail] & 0x1) == 0 && (head < tail) )
{
tail--;
}
int temp = a[head];
a[head] = a[tail];
a[tail] = temp;
}
}
#endif
int aa [] = {0,1,2,3,4,5,6,7,8,9};
void print(int* a, int len)
{
for(int i=0; i< len ;i++)
{
printf("%d ",a[i]);
}
printf("\n");
}
int _tmain(int argc, _TCHAR* argv[])
{
int len = sizeof(aa)/sizeof(aa[0]);
print(aa,len);
fun(aa,len);
print(aa,len);
return 0;
}