Content deleted Content added
Quuxplusone (talk | contribs) →Tail-recursive functions: copyedit; I agree "significance" should come earlier, but it doesn't flow nicely up there |
|||
Line 90:
==Tail-recursive functions==
{{main|Tail recursion}}
Tail-recursive functions are functions ending in a recursive call.
<!-- If someone can rewrite these C functions in Pascal or Common Lisp, please go ahead. -->
Line 133 ⟶ 131:
return count_odds(head->next); /* tail recursion */
}
The significance of tail recursion is that when making a tail-recursive call, the caller's return position need not be saved on the [[call stack]]; when the recursive call returns, it will branch directly on the previously saved return position. Therefore, on compilers which support tail-recursion optimization, tail recursion saves both space and time.
==See also==
|