Skip to content

Commit

Permalink
Create 5-3.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jisunp04023 authored Sep 5, 2023
1 parent 70f08f1 commit dd85f50
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 5-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 예제 5-3
"""
DFS 예제
"""
def bfs(graph, start, visited):
queue = [start] # 큐에 삽입
visited[start] = True # 방문처리

while len(queue):
v = queue.pop(0)
print(v, end = ' ')

for i in graph[v]:
if not visited[i]:
queue.append(i)
visited[i] = True

graph = [[],
[2, 3, 8],
[1, 7],
[1, 4, 5],
[3, 5],
[3, 4],
[7],
[2, 6, 8],
[1, 7]]

visited = [False] * 9

bfs(graph, 1, visited)

0 comments on commit dd85f50

Please sign in to comment.