I have found a solution that was posted some times ago and I have tried to apply it to my exercise but it doesn't work. I have a class graph that has nodes and edges and a method childrenOf that gives all the children of a node. All this works fine. This is my code for the DFS search and I want to find all the paths:
def myDFS(graph,start,end,path=[]):
path=path+[start]
if start==end:
return path
paths=[]
for node in graph.childrenOf(start):
if node not in path:
paths.extend(myDFS(graph,node,end,path))
return paths
I only got empty lists. WHere do I need to look at? When I was doing path=myDFS... in the loop I had at least the last path. I tried path+=myDFS without success. The graph was created with success so it doesn't come from it. Thanks