Mutual recursion: Difference between revisions

Content deleted Content added
Adding a demonstrating drawing
m clean up; http->https (see this RfC) using AWB
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. [httphttps://books.google.com/books?id=olp7lAtpRX0C&pg=PA53&dq=%22mutual+recursion%22 53–55]}} In C:
<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. [httphttps://books.google.co.jpcom/books?id=igJRhp0KGn8C&pg=PA310&dq=%22mutual%20recursion%22 310–313]}}
<source lang=scheme>
(define (count-leaves tree)
Line 132:
== External links ==
* [http://rosettacode.org/wiki/Mutual_recursion Mutual recursion] at [[Rosetta Code]]
* "[httphttps://stackoverflow.com/questions/10295735/example-demonstrating-good-use-of-mutual-recursion Example demonstrating good use of mutual recursion]", "[httphttps://stackoverflow.com/questions/2725038/are-there-any-example-of-mutual-recursion Are there any example of Mutual recursion?]", ''Stack Overflow''
 
[[Category:Theory of computation]]