Don't really have time to go over all of it right now, but it might help us if you show the piece of code where Edge input is found (from a file, I suppose?) and added to the graph.
(P.S.: For a undirected graph, you could simply add an edge "to V2" to V1's and an edge "to V1" to V2's adj.list.)
[edit]
I'm sorry, just realized I've been getting seriously sidetracked. To your original question: (your code)
1 2 3 4 5 6 7 8 9
|
Edge Graph::getEdge(int v1, int v2) const {
list<int>::const_iterator i;
Edge edge(v1, v2);
for (i = ADJACENCY_LIST[v1].begin(); i != ADJACENCY_LIST[v1].end(); ++i) {
if(ADJACENCY_LIST[i].front() == v2)
return edge;
}
return NULL;
}
|
This isn't right. You're looking for (v1, v2), thus you shouldn't be going through ADJ_LIST[i], but always ADJ_LIST[j]. Secondly, you should be checking the entire list, not .front().
You have an iterator 'i' which begins as ADJ[v1].begin() and goes to end(). All you need to do is check the edge pointed to by the iterator and see if it goes to v2.
You can get the element pointed to by dereferncing the iterator, e.g.:
1 2
|
list<int>::iterator i = myList.begin();
cout << *i; // Will print the first int in the list.
|
Thus, all you need to do is to check if "*i == v2".