Skip to content

Instantly share code, notes, and snippets.

@jdmoore7
Created September 13, 2022 21:36
Show Gist options
  • Save jdmoore7/bae4c5788e030e7e81cdead9cf5907a9 to your computer and use it in GitHub Desktop.
Save jdmoore7/bae4c5788e030e7e81cdead9cf5907a9 to your computer and use it in GitHub Desktop.
def traverse(g, node, bfs=True):
s = Staq()
s.insert(node)
scheduled = set([node])
while s.size > 0:
node = s.pop(head=bfs, val=True)
print(node)
neighbors = g[node]
for n in neighbors:
if n not in scheduled:
s.insert(n)
scheduled.add(n)
traverse(graph, 1, bfs=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment