Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. void TND004::stable_partition_iterative(std::vector<int>& V, Test p)
  2. {
  3.  
  4. if( V.size() <= 1 )
  5. return;
  6.  
  7. std::vector<int> evennr;
  8. std::vector<int> oddnr;
  9.  
  10. std::vector<int>::iterator first = V.begin();
  11. std::vector<int>::iterator last = V.end();
  12.  
  13. do
  14. {
  15. if (p(*first)) // first is even
  16. {
  17. evennr.push_back(*first);
  18. }
  19. else
  20. {
  21. oddnr.push_back(*first);
  22. }
  23.  
  24. ++first;
  25.  
  26.  
  27. }
  28. while (first != last);
  29.  
  30. V.clear();
  31.  
  32. std::for_each(evennr.begin(), evennr.end(), [&](int i)
  33. {
  34. V.push_back(i);
  35. });
  36.  
  37. std::for_each(oddnr.begin(), oddnr.end(), [&](int i)
  38. {
  39. V.push_back(i);
  40. });
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement