SHARE
TWEET

Untitled

a guest May 22nd, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. template<typename T>
  6. auto makeUniqueVector(const vector<T> &ref)
  7. {
  8.  
  9.     set<T> copy;
  10.     for(auto it=ref.begin();it!=ref.end();++it)
  11.     {
  12.         copy.insert(*it);
  13.     }
  14.  
  15.     vector<T> newVec;
  16.    
  17.     for(auto it=copy.begin();it!=copy.end();++it)
  18.     {
  19.         newVec.push_back(*it);
  20.     }
  21.     return make_shared<vector<T>>(newVec);
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27.  
  28.  
  29.     vector<int> arr;
  30.     auto size=30;
  31.     for(int i=0;i<size;i++)
  32.     {
  33.         arr.push_back(rand()%10);
  34.     }
  35.     cout<<"Przed funkcja:: "<<endl;
  36.           for(auto i=0;i<size;i++)
  37.     {
  38.                 if(i%5==0)
  39.                     putchar('\n');
  40.         cout<<arr[i]<<" ";
  41.     }
  42.     cout<<"Po funkcji:"<<"\n";
  43.     auto vector=makeUniqueVector(arr);
  44.        
  45.     int i=0;
  46.     for(auto it=vector->begin();it!=vector->end();it++)
  47.     {
  48.         if(++i%5==0)
  49.             putchar('\n');
  50.         cout<<*it<<' ';
  51.     }
  52.  
  53.  
  54.  
  55.     return 0;
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top