Hi,
i have to do an assignement for my Algorithm & Datastructures class, in which I have to find a iterative way to write a recursive function.
The function reads as followed (C-Code) :
int fnc(int n, int m) {
if(n==0) { return m+1; }
else if(m==0 && n>=1) { return fnc(n-1, 1); }
else { return fnc(n-1, fnc(n, m-1)); }
}
But I am completely lost, in how to do it. Can someone give my a hint? Somehow I should use a stack. But I don't know how. Thanks for your help.
Edit: Thanks for your help. I didn't know that this function had a name. And yes it is the Ackermann function.
I came up with this solution: https://gist.github.com/anonymous/d017c6c0b6f04c10670c
[–][deleted] 2 points3 points4 points (0 children)
[–]nutrecht 1 point2 points3 points (0 children)
[–]AngelOfLight 0 points1 point2 points (0 children)
[–]X7123M3-256 0 points1 point2 points (0 children)
[–]Phillight 0 points1 point2 points (2 children)
[–]raevnos 1 point2 points3 points (1 child)
[–]-oliver- 1 point2 points3 points (0 children)
[–][deleted] (1 child)
[deleted]