I know that if a topological sort has the property that all pairs of consecutive vertices in the sorted order are connected by edges, then the topological sort order is unique. My problem is that I can't implement it in C++, especially in the comparison. In the last for I would like to see if in the vetorTop adjacency list is the number next to it in the topological sort. But it seems that in_degree doesnt give me that result. Here follows my code:
int u;
for (int i=1; i<(int)vetorTop.size(); i++){ //topological sorted
u = vetorTop[i];
list<int>::iterator itr;
for (itr = adj[u].begin(); itr != adj[u].end(); itr++){
if (vetorTop[i+1] == in_degree[*itr]++){
cout << "NOT UNIQUE\n";
return;
}
}
}
I would be granteful with any tip and/or advise!