将一整数数列按奇数在前,偶数在后的顺序重新排列,并要求奇偶两部分分别有序.
首页/题库/354℃/2024-05-10 19:10:26
优质解答:
;
#include <algorithm>
#include <iterator>
using namespace std;
bool IsOdd(int n)
{
return n & 1;
}
int main()
{
int a[] = ;
int* beg = a;
int* end = a + sizeof a / sizeof a[0];
sort(beg,end);
stable_partition(beg,end,IsOdd);
copy(beg,end,ostream_iterator<int>(cout," "));
}