compare 2 vectors...

I have two vector, which each contains a pair of ints.

vector<pair<int,int>> A
vector<pair<int,int>> B

Each of them contain a set of coordinate, and i have to check whether coordinate set in A, exist in vector B. The order is arbitrary.. I just need to check the existence of the coordinate in B.

So for instance

vector<pair<int,int>> A = {(1,2),(2,3),(3,4),(4,5)}
vector<pair<int,int>> B = {(4,5),(1,2),(3,4),(2,3)}

the compare function should return true here, even though the pairs in A and B isn't located in the same position.


How would you do this?

If there are no duplicates you could sort the vectors before comparing them.

1
2
3
4
5
6
sort(A.begin(), A.end());
sort(B.begin(), B.end());
if (A == B)
{
	// ...
}
Topic archived. No new replies allowed.