Created
November 12, 2016 16:24
-
-
Save rohithpeddi/5effc7f3b23328f4f09132b36d1bbe59 to your computer and use it in GitHub Desktop.
DFS of EdgeWeightedGraph
This file contains hidden or 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
static class DFS{ | |
boolean[] marked; | |
public DFS(EdgeWeightedGraph G, int source){ | |
marked = new boolean[G.noOfVertices]; | |
dfs(G,source); | |
} | |
public void dfs(EdgeWeightedGraph G, int v){ | |
marked[v] = true; | |
for(int w : G.getAdjVertices(v)){ | |
if(!marked[w]){ | |
dfs(G,w); | |
} | |
} | |
} | |
public boolean hasPathTo(int v){ | |
return marked[v]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment