I was reading about mutual recursion.In almost all the materials,examples of it was problem to determine whether an integer is even or odd?
int is_even(unsigned int n)
{
if (n==0) return 1;
else return(is_odd(n-1));
}
int is_odd(unsigned int n)
{
return (!iseven(n));
}
Obviously above problem can be solved in an easier manner using a modulus operator.
Other example was a problem to find out if a person is female or male.This can also be solved in easier manner without using recursion.
So is the mutual recursion just theoretical or is there anywhere i can use it to practically to make my solution simpler than using any other technique?
Could you please help me out by giving such an example?
Mutual recursion is not very common but it's useful sometimes. Parsing text with the "recursive descent" method is one practical setting where you can find it.