Advertisement
sellmmaahh

tut4-zad5

Jul 21st, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5. template <typename Tip>
  6. bool ImaLi(const Tip &z, const std::vector<Tip> v)
  7. {
  8.     for (auto x: v) {
  9.             if (x==z) return true;
  10. }
  11. return false;
  12. }
  13.  
  14.  
  15.  
  16.  
  17.  
  18. template <typename Tip1>
  19. std::vector <Tip1> Presjek (std::vector<Tip1> v1, std::vector<Tip1> v2)
  20. {
  21.     std::vector <Tip1> v3(0);
  22.     for (auto x: v1)
  23.     {
  24.         if ((ImaLi(x,v2)==true) && (ImaLi(x,v3)==false))
  25.                     v3.push_back(x);
  26.     }
  27.  
  28. return v3;
  29. }
  30. int main () {
  31. std::vector <string> vek1{3,2,1,5,4,6,7,3};
  32. std::vector<string> vek2{3,5,3,6,7,4,2,8,9};
  33. std::cout<<"Presjek vektora: ";
  34. for (auto x: Presjek(vek1,vek2)) std::cout<<x<<" ";
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement