public BreadthFirstSearch(Digraph graph, int node) { if (node >= graph.getVertaxs()) { return; } this.graph = graph; // boolean数组默认都置为false,所以不用专门初始化 boolean[] marked = new boolean[graph.getVertaxs()]; bfs(node, marked); }
public static void main(String[] args) { // 0 1 2 3 4 5 6 7 8 // =================================================== int[][] conn = { {0, 1, 0, 1, 0, 0, 0, 0, 1}, // 0 {1, 0, 0, 0, 0, 0, 0, 1, 0}, // 1 {0, 0, 0, 1, 0, 1, 0, 1, 0}, // 2 {1, 0, 1, 0, 1, 0, 0, 0, 0}, // 3 {0, 0, 0, 1, 0, 0, 0, 0, 1}, // 4 {0, 0, 1, 0, 0, 0, 1, 0, 0}, // 5 {0, 0, 0, 0, 0, 1, 0, 0, 0}, // 6 {0, 1, 1, 0, 0, 0, 0, 0, 0}, // 7 {1, 0, 0, 0, 1, 0, 0, 0, 0} }; // 8 BreadthFirstSearch G = new BreadthFirstSearch(conn); G.bfs(); }