Created
June 22, 2020 04:51
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
List < String > vertices=new ArrayList < > (); | |
Set < String, List < String > > edges=new HashSet(); | |
public void performDFS(graph) | |
{ | |
List < String > vertices=g.getVertices(); | |
Set <String, List < String > > edges=g.getEdges(); | |
visited{};//set of visited graphs | |
for(int i=0;i < v.length; i++){ | |
if(!visited(V[i]) | |
visitIt(v[i]); | |
} | |
} | |
//recursive function | |
public void visitIt(vertex){ | |
visited(vertex)=true; | |
sysout(vertex); | |
//get the edges for this vertex | |
edges=vertex.getEdges(); | |
for(int i=0;i < edges.length; i++){ | |
if(!visited(edges[i]) | |
visitIt(edges[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment