Sorting for equal_range()
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?
Re: Sorting for equal_range()
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.
|All times are GMT +5.5. The time now is 08:40.|