[英]Why does this work even though the function is not called with a pointer to a pointer as a parameter?
[英]Why does this function called: “showTree” work correctly?
这是我不明白的function:
void showTree (node * tree, int cont) {
if (tree == NULL) {
return;
}
else {
showTree (tree-> right, cont + 1);
for (int i = 0; i <cont; i ++) {
cout << " ";
}
cout << tree-> data << endl;
showTree (tree-> left, cont + 1);
}
}
我不明白:
如果 function 总是被递归调用,你如何进入 for 循环?
如果 function 总是被递归调用,树项目如何显示?
如果有人可以向我解释此功能是如何工作的,我将不胜感激。
如果 function 总是被递归调用,你如何进入 for 循环?
如果tree == NULL
,则 function 立即返回,因此它可能会继续进入for
循环。
如果 function 总是被递归调用,树项目如何显示?
output 是由for
循环和下一条语句产生的,所以同理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.