shizaero

Untitled

May 1st, 2023
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 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, typename E>
  10. void FindAndPrint(set<It> container, E element) {
  11.  
  12.     auto item = find_if(container.begin(), container.end(),
  13.         [element](It ele) {
  14.             return ele == element;
  15.         });
  16.    
  17.         for (auto it = container.begin(); it != item; ++it) {
  18.             cout << *it << " "s;
  19.         }
  20.         cout << endl;
  21.  
  22.         for (auto it = item; it != container.end(); ++it) {
  23.             cout << *it << " "s;
  24.         }
  25.         cout << endl;
  26. }
  27.  
  28. int main() {
  29.      set<int> test = { 1, 1, 1, 2, 3, 4, 5, 5 };
  30.      cout << "Test1"s << endl;
  31.      FindAndPrint(test, 3);
  32.      cout << "Test2"s << endl;
  33.      FindAndPrint(test, 0); // элемента 0 нет в контейнере
  34.      cout << "Test3"s << endl;
  35.      FindAndPrint(test, -4);
  36.      cout << "End of tests"s << endl;
  37.  }
Advertisement
Add Comment
Please, Sign In to add comment