Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf9b8dbf

Browse files
ZJUGuoShuaipoyea
authored andcommitted
Correct the wrong iterative DFS implementation (#867)
* Update DFS.py* Update DFS.py
1 parentc2552cd commitf9b8dbf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

‎graphs/DFS.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ def dfs(graph, start):
1818
explored,stack=set(), [start]
1919
explored.add(start)
2020
whilestack:
21-
v=stack.pop()# the only difference from BFS is to pop last element here instead of first one
21+
v=stack.pop()# one difference from BFS is to pop last element here instead of first one
22+
23+
ifvinexplored:
24+
continue
25+
26+
explored.add(v)
27+
2228
forwingraph[v]:
2329
ifwnotinexplored:
24-
explored.add(w)
2530
stack.append(w)
2631
returnexplored
2732

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp