Understanding double recursion

前端 未结 3 1587
执笔经年
执笔经年 2021-01-04 20:03

I\'m able to comprehend recursion easily if there is just one recursive call within a function. However, I am really getting confused when I see two or more recursive calls

3条回答
  •  猫巷女王i
    2021-01-04 20:24

    It seems to me that you have confused the running order of the recursive calls. Keep in mind that, second call (maxval2) does not get called until the first call (maxval1) finishes. maxval1 call itself has two more recursive calls within itself and so on. So without all these inner recursive calls being finished, the program does not reach the maxval2 line.

    Try debugging instead of running the code (in Eclipse for e.g.) and move step by step to see how it actually goes about each recursive call.

提交回复
热议问题