I am looking for a way to transform this recursive function to an iterative one. I have tried thinking about how to actually do it but it hurts me to think about it because I am not really familiar with how to convert from recursive to iterative. If anyone can help me out how to deal with this I would be very grateful.
int function(int row, int col)
{
int* current = &A[row][col];
if (*current == "f") {
return 1;
}
if (*current == ' ') {
*current = '.';
if (function(row, col - 1)){
*current = '.';
return 1;
}
if (function(row + 1, col)){
*current = '.';
return 1;
}
if (function(row, col + 1)){
*current = '.';
return 1;
}
if (function(row - 1, col)){
*current = '.';
return 1;
}
}
return 0;
}