Skip to content

Instantly share code, notes, and snippets.

@sudheesh001
Created November 21, 2013 05:21
Show Gist options
  • Save sudheesh001/7576463 to your computer and use it in GitHub Desktop.
Save sudheesh001/7576463 to your computer and use it in GitHub Desktop.
Strongly Connected Components using single DFS. Print Code segment.
void Graph::printSCCs()
{
stack<int> Stack;
bool *visited = new bool[V];
for(int i = 0; i < V; i++)
visited[i] = false;
for(int i = 0; i < V; i++)
if(visited[i] == false)
fillOrder(i, visited, Stack);
Graph gr = getTranspose();
for(int i = 0; i < V; i++)
visited[i] = false;
while (Stack.empty() == false)
{
// Pop a vertex from stack
int v = Stack.top();
Stack.pop();
// Print Strongly connected component of the popped vertex
if (visited[v] == false)
{
gr.DFSUtil(v, visited);
cout << endl;
}
}
}
@sudheesh001
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment