From 0ef5cbec296495d5c4852a5073961f04db6dc4c4 Mon Sep 17 00:00:00 2001 From: Anirban Chetia Date: Thu, 21 Nov 2019 22:11:24 +0530 Subject: [PATCH] Updated function definitions with comments function definitions - what it does with its type (iterative/recursive) common terms/annotations 2 statements marked as debug, removed other comments (as I kept them while coding) added comments to main function --- Graph/Kosaraju.cpp | 54 ++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/Graph/Kosaraju.cpp b/Graph/Kosaraju.cpp index a9131faa8..ca747bdbc 100644 --- a/Graph/Kosaraju.cpp +++ b/Graph/Kosaraju.cpp @@ -1,12 +1,20 @@ /* Implementation of Kosaraju's Algorithm to find out the strongly connected components (SCCs) in a graph. Author:Anirban166 -*/ +*/ #include #include using namespace std; +/*Common terms/anotations used as parameters in functions below: + V: number of vertices, + adj[]: array of vectors to represent graph, + vis[]: array to keep track of visited nodes, (boolean type) + grev[]: graph with reverse edges. +*/ + +//iterative function/method to print graph: void print(vector a[],int V) { for(int i=0;i a[],int V) cout< &st,bool vis[],vector adj[]) + +//recursive function/method to push vertices into stack passed as parameter: (referenced) +void push_vertex(int v,stack &st,bool vis[],vector adj[]) { vis[v]=true; for(auto i=adj[v].begin();i!=adj[v].end();i++) { if(vis[*i]==false) - calculate_time(*i,st,vis,adj); + push_vertex(*i,st,vis,adj); } st.push(v); } + +//recursive function/method to implement depth first traversal(dfs): void dfs(int v,bool vis[],vector grev[]) { vis[v]=true; @@ -39,18 +51,18 @@ void dfs(int v,bool vis[],vector grev[]) dfs(*i,vis,grev); } } + +//function/method to implement Kosaraju's Algorithm: int kosaraju(int V, vector adj[]) { - // print(adj,V); bool vis[V]={}; stack st; for(int v=0;v