1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

sorting vector values

Discussion in 'C' started by heidik, Nov 9, 2010.

  1. heidik

    heidik New Member

    Joined:
    Oct 23, 2010
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    0
    I am using a vector which has struct type of elements in it. The struct is something like this:

    Code:
    struct block
    {
        std::string id1;
        std::string id2;
        std::string last_line;
    };
    
    The example value of id1 of first vector element is: id1 = 0001VVYF
    The example value of id2 of first vector element is: id2 = 0001VW1S

    AND

    The example value of id1 of second vector element is: id1 = 0001VW1S
    The example value of id2 of second vector element is: id2 = 0001VVYF

    i-e

    1) the value of id1 of first vector element is equal to the value of id2 of second vector element

    2) the value of id2 of first vector element is equal to the value of id1 of second vector element.

    In the program I have to find out whether the IDs of one vector element match the IDs of another vector element. I am not concerned about the id1 and id2. I am concerned about the values they hold in any order. It would be easier to compare if similar values appear against the same id e-g

    The example value of id1 of first vector element is: id1 = 0001VVYF
    The example value of id2 of first vector element is: id2 = 0001VW1S

    AND

    The example value of id1 of second vector element is: id2 = 0001VVYF
    The example value of id2 of second vector element is: id1 = 0001VW1S

    Is it possible to sort the vector this way i-e similar values appear against similar IDs?
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    You don't sort a vector, by definition it's an unsorted set. If you want a sorted set, you have to use a different container than a vector.
     

Share This Page