How to write an iterative version of Ackermanns function in

How to write an iterative version of Ackermann\'s function in pseudocode

Solution

Solution :

Iterative Ackermann Function : ackermann_iterative.c

int fnc_it(int n, int m) {
stack s = NULL;
stk_new(&s);
stk_push(&s, n);
stk_push(&s, m);
stk_push(&s, 0);
int result = -1;
int flag;
while(!stk_isempty(s)) {
flag = stk_top(s);
stk_pop(&s);
m = stk_top(s);
stk_pop(&s);
n = stk_top(s);
stk_pop(&s);
if(flag==0) {
if(n==0) {
result = m+1;
} else if(m==0) {
stk_push(&s, n-1);
stk_push(&s, 1);
stk_push(&s, 0);
} else {
stk_push(&s, n);
stk_push(&s, m);
stk_push(&s, 1);
stk_push(&s, n);
stk_push(&s, m-1);
stk_push(&s, 0);
}
} else if(flag==1) {
stk_push(&s, n-1);
stk_push(&s, result);
stk_push(&s, 0);
}
}
stk_free(&s);
return result;
}
How to write an iterative version of Ackermann\'s function in pseudocodeSolutionSolution : Iterative Ackermann Function : ackermann_iterative.c int fnc_it(int n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site