Content deleted Content added
Adding a demonstrating drawing |
|||
Line 26:
====Basic examples====
A standard example of mutual recursion, which is admittedly artificial, is determining whether a non-negative number is even or is odd by having two separate functions and calling each other, decrementing each time.{{sfn|Hutton|2007|loc=6.5 Mutual recursion, pp. [
<source lang=C>
bool is_even(unsigned int n) {
Line 66:
</source>
A more detailed example in Scheme, counting the leaves of a tree:{{sfn|Harvey|Wright|1999|loc=V. Abstraction: 18. Trees: Mutual Recursion, pp. [
<source lang=scheme>
(define (count-leaves tree)
Line 132:
== External links ==
* [http://rosettacode.org/wiki/Mutual_recursion Mutual recursion] at [[Rosetta Code]]
* "[
[[Category:Theory of computation]]
|