Advertisement
amermo

TP T-5 Z2

Mar 27th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. template <typename IterTip1>
  6. IterTip1 RazmjeniBlokove(IterTip1 pocetak1, IterTip1 kraj1, IterTip1 pocetak2)
  7. {
  8.     while(pocetak1 < kraj1)
  9.         std::swap(*pocetak1++, *pocetak2++);
  10.     return pocetak2;
  11. }
  12.  
  13. int main()
  14. {
  15.     int niz1[5]{1, 1, 1, 1, 1}, niz2[5]{2, 2, 2, 2, 2};
  16.     RazmjeniBlokove(niz1+2, niz1+5, niz2);
  17.     for(auto &x : niz1)
  18.         std::cout << x << " ";
  19.     std::cout << std::endl;
  20.     for(auto &x : niz2)
  21.         std::cout << x << " ";
  22.     std::cout << std::endl;
  23.     std::string s1{"testiramo izmjena"}, s2{"ttttttt"};
  24.     RazmjeniBlokove(s1.begin()+1, s1.end()-10, s2.begin());
  25.     std::cout << s1 << std::endl << s2;
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement