fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. bool comp(int32_t lhs, int32_t rhs) {
  7. if ((lhs ^ rhs) >= 0) {
  8. return false;
  9. }
  10. else
  11. return lhs > rhs;
  12. }
  13.  
  14. int main() {
  15. vector<int32_t> input{9, 4, -2, -1, 5, 0, -5, -3, 2};
  16. // sort +ve, then -ve
  17. stable_sort(input.begin(), input.end(), comp);
  18. for (int32_t i : input)
  19. cout << i << " ";
  20. cout << endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 15248KB
stdin
Standard input is empty
stdout
9 4 5 0 2 -2 -1 -5 -3