+ 1

Who can help me with a code to find duplicates in a vector?

I've always thought of a way to remove the duplicates from a vector, but I found none, can someone help me?

9th Mar 2018, 8:08 AM
Bogdan Laurentiu
Bogdan Laurentiu - avatar
7 Answers
+ 6
You may use a temporary set to remove duplicates from your vector: template<class T> void RemDuplicates(vector<T>& v) { set<T> s; for(int i=0;i<size;++i) s.insert(vec[i]); vec.assign(s.begin(),s.end()); }
9th Mar 2018, 8:20 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
9th Mar 2018, 8:43 AM
jay
jay - avatar
+ 9
What have you tried?
9th Mar 2018, 8:14 AM
jay
jay - avatar
+ 2
ty
9th Mar 2018, 8:45 AM
Bogdan Laurentiu
Bogdan Laurentiu - avatar
+ 1
but every time i have erors that say that i haven't declare that vector
9th Mar 2018, 8:16 AM
Bogdan Laurentiu
Bogdan Laurentiu - avatar
+ 1
the phase is that I do not have to eliminate them, I have to get them out as an answer
9th Mar 2018, 8:23 AM
Bogdan Laurentiu
Bogdan Laurentiu - avatar
0
i've tried to include another vector that don't have duplicates
9th Mar 2018, 8:16 AM
Bogdan Laurentiu
Bogdan Laurentiu - avatar