I am doing a recursive program and during the execution of a recursive function it shows stack overflow error. I cannot proceed without completing this recursive function. Please some one help me... This is the code that i have done:
public void blob(int k, int l, int[,] MV1)
{
while (true)
{
if ((MV1[k, l] == 1) && (status[k, l] != 1))
{
count = count + 1;
if (count < 6000)
{
if (k < xmin)
{
X[Xr, 0] = k;
xmin = k;
}
if (l < ymin)
{
Y[Yr, 0] = l;
ymin = l;
}
if (k > xmax)
{
X[Xr, 1] = k;
xmax = k;
}
if (l > ymax)
{
Y[Yr, 1] = l;
ymax = l;
}
status[k, l] = 1;
if (l != (MV1.Length / MV1.GetLength(0)) - 1)
{
blob(k, l + 1, MV1);
}
if ((l != 0))
{
blob(k, l - 1, MV1);
}
if (k != MV1.Length - 1)
{
blob(k + 1, l, MV1);
}
if ((k != 0))
{
blob(k - 1, l, MV1);
}
}
}