return语句仅结束当前的函数调用。如果是循环调用,仅结束当前层次的调用,并返回上一层次。
对于
int depth(BTree root){
...
if(!root)
return 0;
else{
...
if(ldepth >= rdepth)
return ldepth+1;
else
return rdepth+1;
}
return 1;
}
最后一个“return 1;”不会被执行到的。
你对递归运行要理解深入下
int fact(int n){
int result=1;
if(n=0) return 1;
else result=n*fact(n-1);
return result;
}
当求fact(5) 这个阶乘中fact难道只能执行一次么?