fork(2) download
  1. #include <algorithm>
  2. #include <functional>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <vector>
  6.  
  7. bool is_pos(int i) { return i > 0; }
  8.  
  9. int main()
  10. {
  11.  
  12. int ARRAY[] ={-2,-3,-6,1,2,-8,-7,12,8,9};
  13. int POS_ARRAY[5], NEG_ARRAY[5];
  14. auto p = std::partition(std::begin(ARRAY),
  15. std::end(ARRAY), std::ptr_fun(is_pos));
  16.  
  17. std::copy(std::begin(ARRAY), p, std::begin(POS_ARRAY));
  18.  
  19. std::copy(p, std::end(ARRAY), std::begin(NEG_ARRAY));
  20.  
  21. for(auto i:NEG_ARRAY)
  22. std::cout<<i<<" ";
  23.  
  24. std::cout<<std::endl;
  25.  
  26. for(auto i:POS_ARRAY)
  27. std::cout<<i<<" ";
  28. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
-8 -7 -6 -3 -2 
9 8 12 1 2