I read tail recursion below
Tail recursion refers to a recursive call on the last line. A tail recursion can be mechanically eliminated by placing the body in a while and replacing the recursive call with one assignment per function argument.
for instance
void print(Iterator start, Iterator end, ostream& out=cout) { if(start == end) return; out << *start++ << endl; print(start, end, out); }
converted to iterative according to the above specification as
void print(Iterator start, Iterator end, ostream& out=cout) { while(true) { if(start == end) return; out << *start++ << endl; } }
The passage above mentions that "replacing a recursive call with one assignment with a function argument, but in this example, we had no purpose?
Can someone explain and provide an example for a more detailed explanation of how to translate a recursive iterative function?
source share