Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TND004::stable_partition_iterative(std::vector<int>& V, Test p)
- {
- if( V.size() <= 1 )
- return;
- std::vector<int> evennr;
- std::vector<int> oddnr;
- std::vector<int>::iterator first = V.begin();
- std::vector<int>::iterator last = V.end();
- do
- {
- if (p(*first)) // first is even
- {
- evennr.push_back(*first);
- }
- else
- {
- oddnr.push_back(*first);
- }
- ++first;
- }
- while (first != last);
- V.clear();
- std::for_each(evennr.begin(), evennr.end(), [&](int i)
- {
- V.push_back(i);
- });
- std::for_each(oddnr.begin(), oddnr.end(), [&](int i)
- {
- V.push_back(i);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement