I was just. NET test, for the tail recursion, in debug mode, will not be optimized to non-recursive structure, in release mode, will be optimized to non-recursive structure, there is no stack overflow problem
Stst?
This is my simulation of the file structure class
Stst
?
This is a non-tailed recursive version
Stst
This is the tail-recursive version.
Stst
This is the test code.
Stst
This is the definition of createdir.
Stst
Results:
1, in debug mode, whether it is an ill-ending recursion, will overflow
2, in release mode, the non-tail recursive version will overflow, and the tail recursive version will not overflow
Stst
Modern compilers I think it's all there.
Stst
Because tail recursion is optimized for non-recursive versions, it's a very old technology.
Stst
You can test it under Java, I don't have a Java environment
Stst
Instead of changing your method parameter to the file array type, you can turn recursion into a real tail recursion.
Stst
There's no basis for this.
0xb000:do_ tail recursion (Files)
......
......
Stack:
0xa000:-> Parameters: Files
0xa004:-> return Address: 0xa000
0xa008:? Parameters: Files
0xa012:? --Return Address: 0xa004
0xa016:??? Parameters: Files
0xa020:??? --Return Address: 0xa012
............
The above is the recursive stack structure, the tail recursion has such a fact:
Is that each time recursion, its previous call has been calculated, no need to store intermediate results, so this call can fully use the previous call stack, so the stack structure does not extend downward
An experiment of tail recursion