This is my code snippet for DFS with out recursion in python:
def DFS(graph,start,end):
explored=[]
queue=[[start]]
if start == end:
return "done"
while queue:
path=queue.pop()
node=path[-1]
if node not in explored:
neighbours=graph[node]
for neighbour in neighbours:
new_path=list(path)
new_path.append(neighbour.name)
queue.append(new_path)
if neighbour.name== end:
return new_path
explored.append(node)
return "no path"
This is how my node looks like: class edge: #def init():
def __init__(self,name,value,depth=0):
self.name=name
self.value=value
self.depth=depth
How do I keep track of levels of each node as I've to implement depth limited search without recursion?