mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-31 06:33:44 +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):
|
def bfs(self,s):
|
||||||
queue=[s]
|
queue=[s]
|
||||||
|
self.visited[s]=1
|
||||||
while len(queue)!=0:
|
while len(queue)!=0:
|
||||||
x=queue.pop(0)
|
x=queue.pop(0)
|
||||||
print(x)
|
print(x)
|
||||||
self.visited[x]=1
|
|
||||||
for i in range(0,self.nodes):
|
for i in range(0,self.nodes):
|
||||||
if self.graph[x][i]==1 and self.visited[i]==0:
|
if self.graph[x][i]==1 and self.visited[i]==0:
|
||||||
queue.append(i)
|
queue.append(i)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user