1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
using namespace std;
bool IsOdd (int i) { return ((i%2)!=1); }
bool IsEven (int i) { return ((i%2)==1); }
void EvenOddSort(int myints[], int myint[]);
int main()
{
int myints[] = {1,2,3,4,5,6,7,8,9};
int myint[] = {1,2,3,4,5,6,7,8,9};
EvenOddSort(myints, myint);
system("pause");
}
void EvenOddSort(int myints[], int myint[])
{
int* pbegin = myints;
int* pend = myints+sizeof(myints)/sizeof(int);
pend = remove_if (pbegin, pend, IsEven);
for (int* p=pbegin; p!=pend; ++p)
{
printf("%d ", *p);
}
int* begin = myint;
int* end = myint+sizeof(myint)/sizeof(int);
end = remove_if (begin, end, IsOdd);
for (int* p=begin; p!=end; ++p)
{
printf("%d ", *p);
}
printf("\n");
}
|