Make function non-recursive
Posted
by user69514
on Stack Overflow
See other posts from Stack Overflow
or by user69514
Published on 2010-05-04T13:14:05Z
Indexed on
2010/05/04
13:18 UTC
Read the original article
Hit count: 241
I'm not sure how to make this function non-recursive. Any ideas?:
void foo(int a, int b){
while( a < len && arr[a][b] != -1){
if(++a == len){
a = 0;
b++;
}
}
if( a == len){
size++;
return;
}
if( a < (len-1)){
arr[a][b] = 1;
arr[a][(b+1)] = 1;
foo(a, b);
arr[a][b] = -1;
arr[a][(b+1)] = -1;
}
if( a < (len-1) && arr[(a+1)][b] == -1){
arr[a][b] = 0;
arr[(a+1)][b] = 0;
foo(a,b);
arr[a][b] = -1;
arr[(a+1)][b] = -1;
}
}
© Stack Overflow or respective owner