Sorting values

Hello,
I have a question about sorting the values inside vectors;
I have three vectors V1,V2,and V3, in order to sort the elements ineach vector I know that I can use sort(v.begin(); v.end()) and the question is :
Is there any method that can let me sort the value of V1 but at the same time the corresponding values (i.e.with the same index) in V2 and V3 will be arranged depending on the new position of the elements in V1.
to illustrate my question here is an exemple:
1
2
3
V1[5,2,8,4,3], v2[C1,C2,C3,C4,C5], V3[0.2,0.4,0.25,0.15,0.6]
I want to get:
V1[2,3,4,5,8], v2[C2,C5,C4,C1,C3], V3[0.4,0.6,0.15,0.2,0.25]


thank you for your suggestions
Well, for one thing you could define your own comparison operation on special classes containing the three elements corresponding to each other.

EDIT: Just make a vector of objects containing the three values and make a sorting function that works based on the first value, e.g.:

1
2
3
4
5
6
sort(v.begin(), v.end(),
	[] (const someObject &i, const someObject &j)
	{
		if (i[1] < j[1]) return true;
		else return false;
	});


Something like that?
Last edited on
Topic archived. No new replies allowed.