fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. int main()
  6. {
  7. int pivot = 8;
  8. int arr [9] = {2,1,5,8,9,4,10,15,20};
  9.  
  10. // get partition point
  11. int *pt = std::stable_partition(arr, std::end(arr), [&](int n) {return n < pivot;});
  12.  
  13. // create two vectors consisting of left and right hand side
  14. // of partition
  15. std::vector<int> a1(arr, pt);
  16. std::vector<int> a2(pt, std::end(arr));
  17.  
  18. // output results
  19. for (auto& i : a1)
  20. std::cout << i << " ";
  21. std::cout << '\n';
  22. for (auto& i : a2)
  23. std::cout << i << " ";
  24. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
2 1 5 4 
8 9 10 15 20