(int source)
| 27 | } |
| 28 | |
| 29 | public void BFS(int source) { |
| 30 | Queue<Integer> queue = new LinkedList<Integer>(); |
| 31 | |
| 32 | queue.add(source); |
| 33 | visited[source] = true; |
| 34 | |
| 35 | while (!queue.isEmpty()) { |
| 36 | |
| 37 | int currNode = queue.poll(); |
| 38 | System.out.print(currNode + " "); |
| 39 | |
| 40 | for (int next : this.adj[currNode]) { |
| 41 | if (!visited[next]) { |
| 42 | visited[next] = true; |
| 43 | queue.add(next); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | public void BFS_end() { |
| 50 |