From 803eb3dc5f9a0c25354c17b23fdc562c86527dc7 Mon Sep 17 00:00:00 2001 From: Jin Date: Wed, 17 Apr 2019 23:40:02 +0900 Subject: [PATCH] Update bfs.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 동영상 강의와 같은 코드로 수정 - 강의 주소: https://youtu.be/0v3293kcjTI --- graph/bfs.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/graph/bfs.py b/graph/bfs.py index 750953c..57f29b4 100644 --- a/graph/bfs.py +++ b/graph/bfs.py @@ -1,13 +1,16 @@ __author__ = 'Minsuk Heo' -vertexList = ['A', 'B', 'C', 'D', 'E', 'F', 'G'] -edgeList = [(0,1), (1,2), (1,3), (3,4), (4,5), (1,6)] +vertexList = ["0", "1", "2", "3", "4", "5", "6"] +edgeList = [(0, 1), (0, 2), (1, 0), (1, 3), (2, 0), (2, 4), \ + (2, 5), (3, 1), (4,2), (4, 6), (5,2), (6,4)] graphs = (vertexList, edgeList) def bfs(graph, start): + vertexList, edgeList = graph visitedList = [] queue = [start] + adjacencyList = [[] for vertex in vertexList] # fill adjacencyList from graph @@ -19,9 +22,8 @@ def bfs(graph, start): current = queue.pop() for neighbor in adjacencyList[current]: if not neighbor in visitedList: - queue.insert(0,neighbor) + queue.insert(0, neighbor) visitedList.append(current) return visitedList - -print(bfs(graphs, 0)) - + +print (bfs(graphs, 0))