开发者

what is front end recursion?

I have seen the term as opposed to tail end recursion and I was wondering what the difference between the two was. So basicall开发者_开发百科y What is Front End Recursion?


Front end recursion is when you make the recursive call first in the method, while tail end recursion is when you make the recursive call last in the method.

Example of front end recursion:

void Show(int num) {
  if (num > 0) {
    Show(num - 1);
  }
  Console.WriteLine(num);
}

Result of Show(3);:

0
1
2
3

Example of tail end recursion:

void Show(int num) {
  Console.WriteLine(num);
  if (num > 0) {
    Show(num - 1);
  }
}

Result of Show(3);:

3
2
1
0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜