Update Breadth_First_Search.py

Fixed the fact that all nodes except source are marked as visited twice
This commit is contained in:
mounaim 2017-07-25 16:08:54 +01:00 committed by GitHub
parent 37705510e5
commit 9dcd981a57

View File

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