Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   sorting vector values (http://www.go4expert.com/forums/sorting-vector-values-t23811/)

 heidik 9Nov2010 21:16

sorting vector values

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?

 xpi0t0s 10Nov2010 14:43

Re: sorting vector values

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.

 All times are GMT +5.5. The time now is 17:43.