fork(4) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <algorithm>
  4. #include <iterator>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. int ar[5][2] = { {20, 11}, {10, 20}, {39, 14}, {29, 15}, {22, 23} };
  10. const auto subArraySize = sizeof(*ar);
  11. static const auto SIZE = subArraySize / sizeof(int);
  12.  
  13. qsort(ar, sizeof(ar) / subArraySize, subArraySize, [](const auto lhs, const auto rhs) {
  14. const auto first = reinterpret_cast<const int*>(lhs);
  15. const auto last = next(first, SIZE);
  16. const auto its = mismatch(first, last, reinterpret_cast<const int*>(rhs));
  17.  
  18. if (its.first == last) {
  19. return 0;
  20. } else if (*its.first < *its.second) {
  21. return -1;
  22. } else {
  23. return 1;
  24. }});
  25.  
  26. for (const auto& i : ar) {
  27. for (const auto& j : i) cout << j << '\t';
  28. cout << endl;
  29. }
  30. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
10	20	
20	11	
22	23	
29	15	
39	14