mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-19 00:37:02 +00:00
Update Breadth_First_Search.py
Fixed the fact that all nodes except source are marked as visited twice
This commit is contained in:
parent
37705510e5
commit
9dcd981a57
|
@ -15,10 +15,10 @@ class GRAPH:
|
|||
|
||||
def bfs(self,s):
|
||||
queue=[s]
|
||||
self.visited[s]=1
|
||||
while len(queue)!=0:
|
||||
x=queue.pop(0)
|
||||
print(x)
|
||||
self.visited[x]=1
|
||||
for i in range(0,self.nodes):
|
||||
if self.graph[x][i]==1 and self.visited[i]==0:
|
||||
queue.append(i)
|
||||
|
|
Loading…
Reference in New Issue
Block a user