Advertisement
RobertDeMilo

YB4.7 Обратные итераторы

Nov 11th, 2023 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. template<typename It>
  10. void PrintRange(It range_begin, It range_end)
  11. {
  12.     for (auto it = range_begin; it != range_end; ++it)
  13.     {
  14.         cout << *it << " ";
  15.     }
  16. }
  17.  
  18. int main()
  19. {
  20.     vector <string> langs = { "Python", "C++", "C", "Java", "C#" };
  21.  
  22.     PrintRange(rbegin(langs), rend(langs));
  23.  
  24.     //cout << *rbegin(langs) << endl;
  25.     //cout << *rend(langs) << endl; // нельзя
  26.  
  27.     /*auto it = rbegin(langs);
  28.     cout << *it << " ";
  29.     ++it;
  30.     cout << *it << " ";*/
  31.  
  32.     auto it = find_if(rbegin(langs), rend(langs), [](const string& lang)
  33.         {return lang[0] == 'C'; });
  34.      нашел последний элемент!
  35.  
  36.     sort(rbegin(langs), rend(langs));  сортировка по убыванию
  37.  
  38.     cout << *it << endl;
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement