Advertisement
kutuzzzov

Спринт 4. Урок 5. Итераторы в методах контейнеров

Dec 21st, 2021 (edited)
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. // разработайте сигнатуру фунции MakeVector по аналогии с фунцией MakeSet из урока Задача 3/3
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <set>
  5. #include <string>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. template <typename It>
  11. void PrintRange(It range_begin, It range_end) {
  12.     for (auto it = range_begin; it != range_end; ++it) {
  13.         cout << *it << " "s;
  14.     }
  15.     cout << endl;
  16. }
  17.  
  18. template <typename Container>
  19. void EraseAndPrint(Container& container, int position, int half_interval_1, int half_interval_2) {
  20.     auto it_to_erased = container.erase(container.begin() + position);
  21.     PrintRange(container.begin(), container.end());
  22.     it_to_erased = container.erase(container.begin() + half_interval_1, container.begin() + half_interval_2);
  23.     PrintRange(container.begin(), container.end());
  24. }
  25.  
  26. int main() {
  27.     vector<string> langs = {"Python"s, "Java"s, "C#"s, "Ruby"s, "C++"s};
  28.     EraseAndPrint(langs, 0, 0, 2);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement