Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. bool compare(int a, int b) {
  6.     return a > b;
  7. }
  8.  
  9. int main() {
  10.     std::vector<int> ints = {1, 4, 3, 2, 6, 3};
  11.  
  12.     auto lambda = [](int a, int b){
  13.         return a > b;
  14.     };
  15.  
  16.     //std::sort(ints.begin(), ints.end(), lambda);
  17.     std::sort(ints.begin(), ints.end(), compare);
  18.  
  19.     for (const auto x : ints) {
  20.         std::cout << x << ' ';
  21.     }
  22.     std::cout << "\n\n";
  23.  
  24.     std::vector<std::string> strings = {"ala", "ma", "kota"};
  25.  
  26.     auto printer_lambda = [](const std::string& str) {
  27.         std::cout << str << ' ';
  28.     };
  29.  
  30.     std::for_each(strings.begin(), strings.end(), printer_lambda);
  31.     printer_lambda("dodatkowe!");
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement