Skip to content

Instantly share code, notes, and snippets.

@greekykhs
Created June 22, 2020 04:51
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