Skip to content

Commit

Permalink
Update dfs_recursion.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dremdeveloper authored Oct 1, 2023
1 parent d5c9820 commit d202977
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Algorithm_with_DataStructure/dfs_recursion.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def dfs(graph, start_node):
while stack:
node = stack.pop()
if visited[node] == 0:
print(str(node)+" ") #방문 노드를 출력하기 위한 코드
visited[node] = 1
print(node)
stack.extend(reversed(graph[node])) # reversed를 사용하여 깊이 우선 탐색을 유지
return visited

Expand All @@ -55,4 +55,5 @@ def dfs(graph, start_node):

# DFS 알고리즘 실행
result = dfs(graph, 1)
print(result)
# 출력: 1 2 4 5 3

0 comments on commit d202977

Please sign in to comment.