Registry Mirror
搜索
Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Files
Expand file tree
main
Breadcrumbs
python-algorithm-practice
/
depth_first.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
18 lines (12 loc) · 334 Bytes
main
Breadcrumbs
python-algorithm-practice
/
depth_first.py
Copy path
Top
File metadata and controls
Code
Blame
18 lines (12 loc) · 334 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from breadth_first import get_neighbours
def dfs(g, at = 0):
visited = [False] * len(g)
_dfs(g, visited, at)
def _dfs(g: list, visited: list, at = 0):
if visited[at]:
return
visited[at] = True
print(at)
neighbours = get_neighbours(g, at)
for node in neighbours:
_dfs(g, visited, node)
You can’t perform that action at this time.