Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- template<typename Tip>
- void f(std::vector<Tip> &v) // referenca
- {
- int brojac_izbacenih(0); // ovaj brojac je bitan!
- for(int i=0; i<v.size()-brojac_izbacenih; i++)
- {
- for(int j=i+1; j<v.size()-brojac_izbacenih; j++)
- {
- if(v[i]==v[j])
- {
- int k(j+1);
- while(k<v.size())
- {
- v[k-1]=v[k]; // tebi je bilo v[j]
- k++;
- }
- brojac_izbacenih++; j--; // j-- je bitan kad
- } // ima vise duplikata zaredom
- }
- }
- v.resize(v.size()-brojac_izbacenih); // promjena velicine
- }
- int main()
- {
- std::cout<<"Unesi broj elemenata: ";
- int n;
- std::cin>>n;
- std::cout<<"Unesi elemenate: ";
- std::vector<int> v(n);
- for(int i=0; i<n; i++)
- std::cin>>v[i];
- f(v);
- for(int i=0; i<v.size(); i++)
- std::cout<<v[i]<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement