fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4. using namespace std;
  5.  
  6. int main() {
  7. int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  8.  
  9. auto mid = std::partition(begin(arr), end(arr), [](int x){ return x%2;});
  10.  
  11. auto out = ostream_iterator<int>(cout, ", ");
  12. cout << "odds: ";
  13. copy(begin(arr), mid, out);
  14. cout << "\nevens: ";
  15. copy(mid, end(arr), out);
  16. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
odds: 1, 9, 3, 7, 5, 
evens: 6, 4, 8, 2,