[英]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.