Advertisement
RobertDeMilo

YB4.3 Итераторы множеств и словарей

Nov 10th, 2023
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 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. template<typename It>
  19. void PrintMapRange(It range_begin, It range_end)
  20. {
  21.     for (auto it = range_begin; it != range_end; ++it)
  22.     {
  23.         cout << it->first << "/" << it->second << " ";
  24.     }
  25. }
  26.  
  27. int main()
  28. {
  29.     set<string> langs = { "Python", "C++", "C", "Java", "C#" };
  30.  
  31.     PrintRange(begin(langs), end(langs));
  32.    
  33.     auto it = langs.find("C++");
  34.  
  35.     PrintRange(begin(langs), it);
  36.    
  37.     PrintRange(it, end(langs));
  38.  
  39.     //############################################################################################
  40.  
  41.     map<string, int> langs = { {"Python", 26}, {"C++", 34}, {"C", 45}, {"Java", 22}, {"C#", 17} };
  42.  
  43.     auto it = langs.find("C++");
  44.  
  45.     PrintMapRange(begin(langs), it);
  46.  
  47.     cout << endl;
  48.  
  49.     PrintMapRange(it, end(langs));
  50.  
  51.     //############################################################################################
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement