Advertisement
wowonline

Untitled

Apr 7th, 2022
878
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iterator>
  4. #include <iostream>
  5.  
  6.  
  7. template<typename iter1, typename iter2>
  8. iter2 myremove(iter1 it1_beg, iter1 it1_end, iter2 it2_beg, iter2 it2_end)
  9. {
  10.     std::vector<int> v1_copy;
  11.     for (iter1 it = it1_beg; it != it1_end; ++it) {
  12.         v1_copy.push_back(*it);
  13.     }
  14.  
  15.     std::sort(v1_copy.begin(), v1_copy.end());
  16.     std::unique(v1_copy.begin(), v1_copy.end());
  17.  
  18.  
  19.     std::vector<int>::iterator delete_it = v1_copy.begin();
  20.     while (*delete_it < 0 && delete_it != v1_copy.end()) {
  21.         ++delete_it;
  22.     }
  23.     iter2 write_it = it2_beg;
  24.  
  25.  
  26.     for (iter2 read_it = it2_beg; read_it != it2_end; ++read_it) {
  27.         if (delete_it != v1_copy.end() && *delete_it == std::distance(read_it, it2_beg)) {
  28.             ++delete_it;
  29.         } else {
  30.             std::swap(*write_it, *read_it);
  31.             ++write_it;
  32.         }
  33.     }
  34.  
  35.     return write_it;
  36. }
  37.  
  38.  
  39. // int main()
  40. // {
  41. //     std::vector<int> ind = {1, 2};
  42. //     std::vector<int> v = {1, 2, 15, 40};
  43.  
  44. //     auto it = myremove(ind.begin(), ind.end(), v.begin(), v.end());
  45.  
  46. //     it--;
  47. //     std::cout<<*it--<<std::endl;
  48. //     std::cout<<*it--<<std::endl;
  49. //     std::cout<<*it--<<std::endl;
  50. //     std::cout<<*it--<<std::endl;
  51.  
  52. // }
Advertisement
RAW Paste Data Copied
Advertisement