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))