尾递归

尾递归:

  

https://en.wikipedia.org/wiki/Tail_call

'Tail calls can be implemented without adding a new stack frame to the call stack'

如果语言对尾递归的情况做过优化,那么在调用时候可以不增加栈帧,达到优化的目的。

拿斐波那契额数列举例:

在最后return的一行,可能会进入递归计算,导致调用栈占用空间太大

如果return后面直接跟的是这个函数本身,我们称它为尾递归 

原文地址:https://www.cnblogs.com/eret9616/p/11370165.html