【发布时间】:2014-02-25 00:09:33
【问题描述】:
请解释一下 return 语句是如何对 trie 进行简单递归解析的
案例一:
if (true) push &stack; //push path result onto a stack
else{
if (terminating condition true) return;
else {
condition 1 recursion to next node
condition 2 recursions to next node
...
condition n recursion to next node
}
recursion to next path;
}
案例 B:
if (true) {
push &stack; //push path result onto a stack
return;
}else{
if (terminating condition true) return;
else{
condition 1 recursion to next node
condition 2 recursion to next node
...
condition n recursion to next node
}
recursion to next path;
}
案例 A 对我来说效果很好。但是,我不明白将结果推送到堆栈后会发生什么。 “它”如何知道终止这些路径?
【问题讨论】:
-
那么你知道递归fn的工作原理吗?
-
@555k 我不确定你所说的“知道递归 fn 的工作原理”是什么意思