Skip to content

Commit be64384

Browse files
committed
Create 9_BreadthFirstSearch module
1 parent 7d9cac4 commit be64384

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

‎.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"python.linting.pylintEnabled": false,
3+
"python.linting.flake8Enabled": true,
4+
"python.linting.enabled": true
5+
}
+12-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
def bfs(data, start, visited=set()):
22

33
queue = [start]
4-
4+
55
while queue:
66
current_node = queue.pop(0)
7-
if current_node not in visited: print(current_node, end = " ")
7+
if current_node not in visited:
8+
print(current_node, end=" ")
89
visited.add(current_node)
9-
10+
1011
for i in data[current_node] - visited:
1112
queue.append(i)
12-
1313
return
14-
14+
15+
1516
if __name__ == '__main__':
16-
17-
data = {'A': {'B'},
18-
'B': {'A', 'C', 'D'},
19-
'C': {'B', 'E'},
20-
'D': {'B', 'E'},
21-
'E': {'C', 'D', 'F'},
22-
'F': {'E'}}
23-
17+
18+
data = {
19+
'A': {'B'}, 'B': {'A', 'C', 'D'}, 'C': {'B', 'E'}, 'D': {'B', 'E'},
20+
'E': {'C', 'D', 'F'}, 'F': {'E'}
21+
}
22+
2423
bfs(data, 'A')

0 commit comments

Comments
 (0)