Interaction Recursion
So far, we have seen recursive functions that call ourselves directly. Although most recursive functions comply with this form, recursion is more widely defined. If a function is subdivided into several subfunctions, you can apply recursive calls at a deeper nesting level. For example, if function f calls function g and function g calls function f in turn, these functions are still called as recursion. This type of recursion becomes interactive Recursion
The following code uses an even number or an odd number to demonstrate the application of recursive interaction. This question highlights the importance of trust in recursive jump.
First, first look at the description of the odd and even numbers:
If the previous number of a number is an odd number, the number is an even number.
A tree is an odd number if it is not an even number.
Define 0 as an even number
Recursive jump Trust
From the code, we can see that the implementation of the code is completely based on the three points described in the preceding odd and even numbers. At first glance, this is incredible. If you want to explore how it is implemented at the underlying layer, you only need to use a small number to import the data.
For example, simply looking at the surface, the simple scenario of "defining 0 as an even number" cannot tell whether this recursion works correctly. Therefore, what we need for such a situation that cannot be seen at once is the trust of recursive jump. As long as the recursive decomposition is correct and the simple scenario analysis is correct, we don't have to worry about the implementation details, hand it over to the computer. Therefore, as long as you master recursive thinking, how simple, fast, and shocking to solve a problem
[Cpp]
# Include <iostream>
Using namespace std;
Bool isodd (unsigned );
Bool isodd (unsigned n)
{
Return! (Iseven (n ));
}
Bool iseven (unsigned n)
{
If (n = 0)
{
Return true;
}
Else
{
Return isodd (n-1 );
}
}
Int main ()
{
Cout <isodd (11) <endl;
Return 0;
}