Original question: the output result of the following code is
# Include <stdio. h>
Int a = 0; int count = 0;
Void MysteryFunc (int B ){
If (B = 0 ){
Count ++;
Printf ("% d: % d \ n", count, );
}
A = a + B;
For (int I = B-1; I> = 0; -- I)
MysteryFunc (I );
}
Void main (){
MysteryFunc (5 );
Printf ("\ n % d \ n", );
}
Analysis: The first output parameter count is changed only when B = 0 and increases by 1 by count ++. Therefore, this value can be ignored.
A careful analysis of the title is recursive + loop. For each recursive number, it is recursive from itself to 0. In particular, note that the new recursive number generated in the recursion process will be recursive in sequence,
The typical full binary tree structure is as follows:
As described above, the full binary tree is traversed in the forward Order (that is, the "first order traversal" in the figure) and summed to the corresponding leaf node. Result:
1: 15
2:
3:16
4:
5: 19
6:
7: 20
8: 20
9:
10: 26
11: 27
12: 27
16: 31
31 ---- don't forget there is another 31 (printf ("\ n % d \ n", );)
Challenge: We look forward to a better solution!
Author: "BlankHole"