(visited, graph, node)
| 12 | queue = [] #Initialize a queue |
| 13 | |
| 14 | def bfs(visited, graph, node): |
| 15 | visited.append(node) |
| 16 | queue.append(node) |
| 17 | |
| 18 | while queue: |
| 19 | s = queue.pop(0) |
| 20 | print(s, end=" ") |
| 21 | |
| 22 | for neighbour in graph[s]: |
| 23 | if neighbour not in visited: |
| 24 | visited.append(neighbour) |
| 25 | queue.append(neighbour) |
| 26 | |
| 27 | # Driver Code |
| 28 | bfs(visited, graph, 'A') |