Skip to content
Snippets Groups Projects
Commit 53e1ea29 authored by Lawrence Chung's avatar Lawrence Chung
Browse files

DepthFirstSearch pre-test

parent 134e5848
No related branches found
No related tags found
No related merge requests found
......@@ -2,4 +2,28 @@ package search;
public class DepthFirstSearch {
private boolean[] marked;
private int count;
public DepthFirstSearch(GraphBuild G, int s){
marked = new boolean[G.V()];
dfs(G, s);
}
public void dfs(GraphBuild G, int v){
marked[v] = true;
count++;
for(int w : G.adj(v))
if(!marked[w])
dfs(G, w);
}
public boolean marked(int w){
return marked[w];
}
public int count(){
return count;
}
}
......@@ -12,6 +12,9 @@ public class GraphBuild {
GraphBuild gb = new GraphBuild(5);
System.out.println(gb.V());
System.out.println(gb.E());
for(int i = 0; i < gb.adj.length; i++){
System.out.println(gb.adj[i]);
}
}
public GraphBuild(int V){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment