Skip to content

Commit 4517aea

Browse files
committed
Fixed bug in breadth-first search
1 parent f20d1b0 commit 4517aea

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

breadth_first_search.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def breadth_first_search(from_city, to_city, city_data):
3838

3939
while to_visit != []:
4040
current = to_visit.popleft() # Treat to_visit as queue
41-
visited.add(current)
41+
print("Visiting:", current)
4242
neighbors = city_data[current].keys()
4343

4444
for n in neighbors:
@@ -48,6 +48,7 @@ def breadth_first_search(from_city, to_city, city_data):
4848

4949
elif n not in visited:
5050
parent_map[n] = current
51+
visited.add(n)
5152
to_visit.append(n)
5253

5354
return None

0 commit comments

Comments
 (0)