fork download
  1. bool first_goes_to_left_of(int first, int second) {
  2. if (first %2 == 0) { //if first is even
  3. if (second %2 == 0) //and second is even
  4. return first < second; //sort by increasing order
  5. else //and second is odd
  6. return true; //first goes to left
  7. } else { //if first is odd
  8. if (second %2 == 0) //and second is even
  9. return false; //second goes to left
  10. else //and second is odd
  11. return second < first; //sort by decreasing order
  12. }
  13. }
  14.  
  15. #include <algorithm>
  16. #include <iostream>
  17. #include <iterator>
  18.  
  19. int main() {
  20. int a[10]={4,6,9,1,2,3,7,5,8,0};
  21. std::sort(a, a+10, first_goes_to_left_of);
  22. std::copy(a, a+10, std::ostream_iterator<int>(std::cout, " "));
  23. }
Success #stdin #stdout 0s 2888KB
stdin
Standard input is empty
stdout
0 2 4 6 8 9 7 5 3 1