1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

sorting vector values

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

  1. heidik

    heidik New Member

    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

    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