Advertisement
Guest User

Lambda sort

a guest
Feb 18th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. //g++  5.4.0
  2. #include <algorithm>
  3. #include <vector>
  4. #include <iostream>
  5.  
  6. #define I 4
  7. #define J 2
  8.  
  9. using namespace std;
  10.  
  11. struct matched_row
  12. {
  13.   int arr[J];
  14.   int max;
  15. };
  16.  
  17. int main()
  18. {
  19.     int matrix[I][J]{{3, 4}, {5, 6}, {7, 8}, {9, 10}};
  20.    
  21.     vector<matched_row> matched;
  22.     matched_row mr;
  23.     copy(begin(matrix[2]), end(matrix[2]), begin(mr.arr));
  24.     mr.max = 8;
  25.     matched.push_back(mr);
  26.     copy(begin(matrix[3]), end(matrix[2]), begin(mr.arr));
  27.     mr.max = 10;
  28.     matched.push_back(mr);
  29.    
  30.     sort(matched.begin(), matched.end(), [](matched_row &i, matched_row &j)->bool{ return (i.max < j.max); });
  31.    
  32.     cout << matched[0].max;
  33.    
  34.     return 1;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement