Advertisement
amermo

Samostalni 4 - Z38

Mar 25th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template <typename TipElemenata>
  5. void Odstrani(std::vector<TipElemenata> &v, TipElemenata mini, TipElemenata maxi)
  6. {
  7.     for(unsigned int i(0); i < v.size(); i++)
  8.     {
  9.         if(v[i] < mini || v[i] > maxi)
  10.         {
  11.             v.erase(v.begin()+i);
  12.             i--;
  13.         }
  14.     }
  15. }
  16.  
  17. int main()
  18. {
  19.     std::vector<int> v {3, 8, 5, 6, 1, 4, 9, 7, 2, 2, 6, 4, 9, 1, 4, 8, 3, 6, 5};
  20.     int mini(3), maxi(7);
  21.     Odstrani(v, mini, maxi);
  22.     for(const auto &x : v)
  23.         std::cout << x << " ";
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement