Possible Duplicate:
Can all iterative algorithms be expressed recursively?
Is it always possible to convert a iterative function in a recursive function?
Possible Duplicate:
Can all iterative algorithms be expressed recursively?
Is it always possible to convert a iterative function in a recursive function?
Depends on what the function do.
Of course you can, though, add this to your function:
void f(...) {
if(false) f(...)
else { processing }
}
In this case the second function is recursive, but recursion never happens.
As far as I know yes, this is possible. The other way around is also possible, but in that case you may need to use appropriate data structures such as a stack.
Algorithm and implementation of an algorithm are two different things. The term recursion also means different things, depending on whether it is applied to the algorithm itself or to its specific implementation. It is not clear from your question which one you are talking about.
It is always possible to convert recursive implementation into iterative implementation, where "recursive" and "iterative" are just syntactic properties of a program written in a procedural language, like C or C++.
It is generally impossible to turn recursive algorithm into an iterative algorithm, where "recursive" and "iterative" describe the fundamental structure of the algorithm itself.
All iterative functions can be made recursive and vice versa. In functional languages it is common practice to rewrite iterative loops as tail-recursion. As long as the functional language is Turing-complete, and they all are, then it can compute any computable function. Therefore, any loop can be expressed iteratively.
The usual way an iterative function works looks something like this:
function iterative(args)
while not done_with(args)
args = transform(args)
end while
return args
end function
once you have transformed an iterative function into this form, it can then be trivially transformed into a recursive function like so:
function recursive(args)
if done_with(args)
return args
else
return transform(args)
end if
end function