Compare vector of pair!
I have a vector of pair i.e., vector<pair<int,int>>graph; which has data like this: 1 0 2 1 1 2 3 2 I want to make adjacency list like : ( 1, 0) -> ( 2, 1) ( 1, 2) ( 2, 1) -> ( 1, 0) ( 1, 2) ( 1, 2) -> ( 1, 0) ( 2, 1) ( 1, 2) ( 3, 2) -> ( 2, 1) (1, 2) If one of the element of pair is a part of second pair. It should be a part of adjacency list. I tried this, vector<pair<int,int>>graph2(totalnode); while (input >> node1 >> node2) { graph2.push_back(make_pair(node1,node2)); } vector<pair<int,int>>::iterator firstloop; vector<pair<int, int>>::iterator secondloop; for(firstloop = graph2.begin();firstloop != graph2.end(); firstloop++) { for (secondloop = graph2.begin(); secondloop != graph2.end(); secondloop++) { if (graph2[firstloop].first == graph2[secondloop].first || graph2[firstloop].first == graph2[secondloop].second || graph2[firstloop].second == graph2[secondloop].first || graph2[firstloop].second == graph2[secondloop].second) { } } } But this is not right, what can I do for that. And once I found the matching element, where do I save it ( in another vector of pair?).