Skip to content

Instantly share code, notes, and snippets.

@yask123
Created April 21, 2015 07:57
Show Gist options
  • Select an option

  • Save yask123/7cbafd05894f129e359e to your computer and use it in GitHub Desktop.

Select an option

Save yask123/7cbafd05894f129e359e to your computer and use it in GitHub Desktop.
graph = {'0': set(['1', '2']),
'1': set(['2']),
'2': set(['0', '3']),
'3': set(['3'])}
visited = {}
for each in graph:
visited [each]=False
queue = []
s = '2'
queue.append(s)
while len(queue):
visited[s]=True
s= queue.pop(0)
print s
for each in graph[s]:
if not visited[each]:
visited[each]=True
queue.append(each)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment