Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public DepthFirstSearch(Graph g, int rootVertex)
- {
- checked = new boolean[g.verticesInGraph()];
- exploreFromVertex(rootVertex, g);
- }
- //Go through the graph from vertex vertex until all connected vertices are explored
- private void exploreFromVertex(int vertex, Graph myGraph)
- {
- checked[vertex] = true; //Mark the vertex as checked or explored
- for(int x : myGraph.getVerticesConnectedTo(vertex))
- {
- if(!checked(x))
- {
- //Call this method recursively if node is not checked
- exploreFromVertex(x, myGraph);
- }
- }
- }
- public boolean checked(int vertex)
- {
- return checked[vertex];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement