【发布时间】:2018-08-06 12:07:48
【问题描述】:
我想知道如何编写对遍历有副作用的迭代 DFS?
function DFS(x) {
x.in = time++ // this is obvious
foreach (child in x.children) {
DFS(child)
}
x.out = time++ // it looks problematic
}
time 通过引用访问(因此与所有foo 调用共享)。
【问题讨论】:
-
而 Foo() 和 DFS() 之间的联系是 .... ?
-
为什么会有问题?
标签: algorithm recursion graph iteration