算法碎片知识整理

图:

深度优先搜索:

    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 ;

}

}

 

}

 

 

广度优先搜索:

posted @ 2015-03-11 13:36  NYK  阅读(188)  评论(0编辑  收藏  举报