开发者

what is front end recursion?

开发者 https://www.devze.com 2023-03-11 01:27 出处:网络
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 y

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

精彩评论

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