标签:
图:
深度优先搜索:
public class DFS{
private boolean[] marked;
pirvate int count;
public DepthFirstSearch(Graph G, int s ){
marked = new boolean[G.V()];
dfs.(G,s);
}
private void dfs(Graph 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 ;
}
}
}
广度优先搜索:
标签:
原文地址:http://www.cnblogs.com/ykong/p/4329663.html