I have the following recursive implementation of the fill algorithm:
I'm wondering, is this efficient? I read that the recursion doesn't slow things down in this case as much as it does in other algorithms, is this true?
void fill(int x, int y)
if ( mat[x][y] == 0 )
mat[x][y] = 1;
Would an interative approach give a significant increase in speed? Is it worth implementing it iteratively, and if so, how would I approach that?
you don't check bounds
you use global variable (are you sure you need it?)
recursion does not slow things down only if it is optimized by compiler...
> I'm wondering, is this efficient?
No. It uses stupid amounts of stack space for even simple shapes.
Do a web search for "scanline fill algorithm".