diff --git a/chapter6/ex6.1.py b/chapter6/ex6.1.py index 52e9b53..88b0e06 100644 --- a/chapter6/ex6.1.py +++ b/chapter6/ex6.1.py @@ -21,7 +21,7 @@ graph = { "f": [], } -visited = [] +visited = set() def bfs(): @@ -36,7 +36,7 @@ def bfs(): if current_node.name in visited: continue - visited.append(current_node.name) + visited.add(current_node.name) next_nodes = graph[current_node.name] for node in next_nodes: diff --git a/chapter6/ex6.2.py b/chapter6/ex6.2.py index cebf63d..c2f74b7 100644 --- a/chapter6/ex6.2.py +++ b/chapter6/ex6.2.py @@ -21,7 +21,7 @@ graph = { "bat": [], } -visited = [] +visited = set() def bfs(): @@ -36,7 +36,7 @@ def bfs(): if current_node.name in visited: continue - visited.append(current_node.name) + visited.add(current_node.name) next_nodes = graph[current_node.name] for node in next_nodes: