Advertisement
chevengur

CПРИНТ № 5 | Итераторы | Урок 3: Концепция полуинтервалов 2/2

Dec 25th, 2023
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <set>
  6.  
  7. using namespace std;
  8.  
  9. template <typename it>
  10. void PrintRange(it begin, it end){
  11.     for(auto iterator = begin; begin!= end; ++iterator, ++begin){
  12.         cout << *iterator << " ";
  13.     }
  14.     cout << endl;
  15. }
  16.  
  17. template <typename con, typename elem>
  18. void FindAndPrint(con start_, elem num){
  19.     auto begin_con = begin(start_);
  20.     auto end_con = end(start_);
  21.     auto stop_con = find(begin_con, end_con, num);
  22.  
  23.     PrintRange(begin_con, stop_con);
  24.     PrintRange(stop_con, end_con);
  25. }
  26.  
  27. int main() {
  28.     set<int> test = {1, 1, 1, 2, 3, 4, 5, 5};
  29.     cout << "Test1"s << endl;
  30.     FindAndPrint(test, 3);
  31.     cout << "Test2"s << endl;
  32.     FindAndPrint(test, 0); // элемента 0 нет в контейнере
  33.     cout << "End of tests"s << endl;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement