Sorting for equal_range()

Discussion in 'C' started by heidik, Jan 15, 2012.

  1. heidik

    heidik New Member

    Joined:
    Oct 23, 2010
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice