Advertisement
sellmmaahh

t7-zad3

Apr 23rd, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include<iostream>
  2. #include <list>
  3. #include <algorithm>
  4.  
  5. template <typename T>
  6.  std::set<T>  Unija ( const std::set<T> &s1, const std::set<T> &s2)
  7.  {  std::set<T> s3;
  8.      auto it1(s1.begin());
  9.      auto it2(s2.begin());
  10.      while (it1!=s1.end() && it2!=s2.end()) {
  11.         if (*it1<*it2)
  12.         s3.insert(*it1++);
  13.         if (*it2<*it1)
  14.             s3.insert(*it2++);
  15.         else
  16.         { s3.insert(*it1++);
  17.         it2++;
  18.        
  19.      }
  20.      while (it1!=s1.end())
  21.      {
  22.          s3.insert(*it1++);
  23.      }
  24.      while (it2!=s2.end())
  25.         s3.insert(*it2++);
  26.        
  27.      return s3;
  28.  }
  29.  
  30.  template <typename selma>
  31.  std::set <selma> Presjek (const std::set<selma> &s1, const std::set<selma> &s2)
  32.  {
  33.      std::set<selma> s3;
  34.      auto it1(s1.begin()); auto it2(s2.begin());
  35.      while (it1!=s1.end() && it2!=s2.end()) {
  36.         if(*it1<*it2)
  37.             it1++;
  38.         if (*it2<*it1)
  39.             it2++;
  40.         else {
  41.             s3.insert(*it1++);
  42.             i2++;
  43.         }
  44.      }
  45.      return s3;
  46.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement