Sorting for equal_range()

heidik's Avatar, Join Date: Oct 2010
Contributor
Hello all

I am using 3 vectors each of which is of type struct "ABC". I am trying to find duplicates in each vector using equal_range() method. In order for equal_range() to work, the vectors must be sorted. The criteria for sorting each vector is different, therefore, I can't write a single sort method inside the struct "ABC". Is there any way to write different methods for sorting, one for each vector?

Many Thanks
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Sorting is a very expensive way of finding duplicates. The simplest algorithm for finding duplicates is to compare every element with every other element - like a bubble sort, but without the swaps.

There is a quicker way of spotting duplicates, which is to drop a copy or representation of each object in the vectors into a sorted list. On each drop, check if the object already exists, and if it does then there's your duplicate.