简单地说,递归停止了一半,尽管其他一切都很好。在
递归函数如下所示(整个代码可以找到here):
def DFS(graph, startNode = 0):
global nodesProcessed; global explored; global finishingTime
explored[startNode] = True
currentLeader = startNode
if startNode in graph:
for neighbor in graph[startNode]:
if not explored[neighbor]:
#checkpoint 1
DFS(graph, neighbor)
#checkpoint 2
else: return currentLeader
nodesProcessed += 1
finishingTime[startNode] = nodesProcessed
return currentLeader
问题是经过一段时间的递归后,它停止了。让我困惑的是:
checkpoint 1
,但未能到达checkpoint 2
,并且该递归根本不执行sys.setrecursionlimit(10**6)
这让我抓狂,我看不出它为什么不工作,没有错误,没有堆栈溢出,只是停止,说Press any key to continue ...
好像它完成了。有人知道可能出什么问题吗?在
正如documentation指定的那样:
有一个script来检查这个限制。在
您必须实现非递归DFS。在
相关问题 更多 >
编程相关推荐