First, one OC recursion:
-(int) sum: (int) num { if0) { return num; } return 1 ];}
The write recursive algorithm only needs to remember two points:
1. There is a clear export
2. When you do not meet the conditions of export, you call yourself
Follow the above ideas with block rewrite:
Static int (^sumblock) (int) = ^ (int num) { if0) { return num; } return 1
Note that to do this yourself, you need to be able to accurately find the ' block ' function entry in memory, so you need to use the ' static ' modifier symbol, and nothing else.
In addition, if asked in the interview, be sure to say:
1. Each time you call yourself, the system will open a stack frame record temporary variables and parameters
2. Too many recursion times, stack overflow error will occur
3. Recursive algorithm is not recommended in mobile development, and now the main thread stack area is only 512K
The above test code calls NSLog(@ "%d", Sumblock (1024x768 )); There will be a stack overflow error
Ios:block Write recursion