Skip to content

Commit

Permalink
Update dfs_stack.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dremdeveloper authored Oct 2, 2023
1 parent a2414f7 commit b01b1e7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Algorithm_with_DataStructure/dfs_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
def dfs(graph, start_node):
visited = [False] * (len(graph) + 1)
stack = [start_node]
visited[start_node] = True;

while stack:
node = stack.pop()
visited[node] = True;
print(node)

for adj_node in graph[node]: # 인접한 노드 방문
if not visited[adj_node]:
stack.append(adj_node)
visited[adj_node] = True;


# 그래프를 인접 리스트로 표현
Expand Down

0 comments on commit b01b1e7

Please sign in to comment.