0

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!

sink
  • 23
  • 7
  • Welcome to Stack Overflow. I advise you to look at the [hep section](http://stackoverflow.com/help). You have not given us enough information to answer this question, or even understand it. – Beta Mar 23 '17 at 01:54
  • I hope its clearer and that you can help me @Beta – sink Mar 23 '17 at 02:20
  • Where is in_degree defined and populated? – bichito Mar 23 '17 at 03:39
  • There are several things that *might* be wrong here, but I can't be sure because I don't know what these variables contain, nor what they ought to contain. What does the value of an element in `in_degree` mean, and why do you increment it? Voting to close. – Beta Mar 23 '17 at 23:56

0 Answers0