Is every recursive function convertible to iteration? What characteristic should a recursive function have in order for it to be implemented using iteration?
<
It is generally possible to convert any recursive algorithm into loop. The method is simple: we can imitate how the compiler generate code for function call: entering function, returning from function, and continue execution.
To turn a recursive function into an iterative loop, you can:
The whole process above is done in a while loop, which will exit when the stack is empty,