Advertisement
jasonpogi1669

Sorting with Lambda Function using C++

Jul 20th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.     int a[n];
  9.     for (int i = 0; i < n; i++) {
  10.         cin >> a[i];
  11.     }
  12.     sort(a, a + n, [](const int& a, const int& b) -> bool {
  13.         // write condition below
  14.        return a > b; // sort in non-increasing order
  15.     });
  16.     for (int i = 0; i < n; i++) {
  17.         cout << a[i] << " ";
  18.     }
  19.     cout << '\n';
  20.     return 0;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement