// 奇数在前,偶数在后,
#include <iostream>
#include <assert.h>
#include <algorithm>
using namespace std;
void swapIntArr(int *an, int n)
{
assert(NULL !=an);
int *p1=an, *p2=an+n-1;
while (p1 < p2)
{
while (*p1 %2 !=0)
{
p1++;
}
while (*p2 %2 == 0)
{
p2--;
}
int t=*p1;
*p1=*p2;
*p2=t;
p1++;
p2--;
}
}
int main()
{
int an[]={3,5,2,5,2,6,8,3,25,65,67,78,34,2,32,3};
int n=sizeof(an)/sizeof(int);
copy(an,an+n,ostream_iterator<int>(cout, " "));
cout<<endl;
swapIntArr(an,n);
copy(an,an+n,ostream_iterator<int>(cout, " "));
cout<<endl;
return 0;
}
整数数组,奇数在前,偶数在后。