fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <memory>
  4.  
  5. typedef std::pair<int,int> Pair;
  6.  
  7. bool compare(const Pair& i, const Pair& j) { return i.first < j.first; }
  8.  
  9. int main() {
  10. const int N=5;
  11. Pair pairs[N] = {{1,2}, {7,8}, {13,14}, {4,5}, {10,11}};
  12.  
  13. std::cout << "unsorted" << std::endl;
  14. for(int i=0; i<N;++i) std::cout << i << ": (" << pairs[i].first << ", " << pairs[i].second << ")" << std::endl;
  15.  
  16. std::sort(pairs, pairs+N, compare);
  17.  
  18. std::cout << "sorted" << std::endl;
  19. for(int i=0; i<N;++i) std::cout << i << ": (" << pairs[i].first << ", " << pairs[i].second << ")" << std::endl;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
unsorted
0: (1, 2)
1: (7, 8)
2: (13, 14)
3: (4, 5)
4: (10, 11)
sorted
0: (1, 2)
1: (4, 5)
2: (7, 8)
3: (10, 11)
4: (13, 14)