I need to remove duplicates from a large unsorted vector of size 8 million elements of the following form:
vector<unsigned> unsortedVec;
I need to retain the position of the unsorted elements after removing duplicates. For example, if my unsortedVec is:
6,98,1,938,98,736,0,1
Then after removing duplicates my unsorted vector should be:
6,98,1,938,736,0
i.e. only the later duplicate values are deleted and the order of the elements remain as it is.
For doing so I tried to create a set of unique elements present in the vector "unsortedVec" and continued iterating, if the elements were already present in the set then I did not insert them in "unsortedVec". Given the size of my unsortedVec, this is turning to be very slow. Is there some way by which I may delete duplicate elements from unsorted vec.
I tried the approach marked as duplicate question, however that too is turning to be very slow