Created
November 21, 2013 05:21
-
-
Save sudheesh001/7576463 to your computer and use it in GitHub Desktop.
Strongly Connected Components using single DFS. Print Code segment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have a look at this. https://sites.google.com/site/indy256/algo/scc_tarjan