snippets/graph/ShortestPath/acyclicGraph.cpp
void Graph::topologicalSortUtil(int v, bool visited[], stack<int> &Stack)
{
    // Mark the current node as visited
    visited[v] = true;

    // Recur for all the vertices adjacent to this vertex
    list<AdjListNode>::iterator i;
    for (i = adj[v].begin(); i != adj[v].end(); ++i)
    {
        AdjListNode node = *i;
        if (!visited[node.getV()])
            topologicalSortUtil(node.getV(), visited, Stack);
    }

    // Push current vertex to stack which stores topological sort
    Stack.push(v);
}
// A recursive function used by shortestPath. See below link for details
// http://www.geeksforgeeks.org/topological-sorting/
A recursive function used by shortestPath.
A recursive function used by shortestPath .
void Graph::topologicalSortUtil(int v, bool visited[], stack<int> &Stack)
{
    visited[v] = true;
    list<AdjListNode>::iterator i;
    for (i = adj[v].begin(); i != adj[v].end(); ++i)
    {
        AdjListNode node = *i;
        if (!visited[node.getV()])
            topologicalSortUtil(node.getV(), visited, Stack);
    }
    Stack.push(v);
}
void Graph :: topologicalSortUtil ( int v , bool visited [ ] , stack < int > & Stack ) { visited [ v ] = true ; list < AdjListNode > :: iterator i ; for ( i = adj [ v ] . begin ( ) ; i != adj [ v ] . end ( ) ; ++ i ) { AdjListNode node = * i ; if ( ! visited [ node . getV ( ) ] ) topologicalSortUtil ( node . getV ( ) , visited , Stack ) ; } Stack . push ( v ) ; }
A recursive function used by shortestPath.
A recursive function used by shortestPath .
// Mark the current node as visited // Recur for all the vertices adjacent to this vertex // Push current vertex to stack which stores topological sort