How to find the largest contiguous region in a 2D array in C++

  2d, arrays, c++

So I’m working on a project where I need to find the largest contiguous region of a 2D array that has the same element. So far I’ve tried to use two for loops but haven’t been able to get the results I want. Any help would be greatly appreciated.

Here’s the code I’ve tried so far:

for (int i = 0; i < 15; i++)
{
    for (int j = 0; j < 15; j++)
    {
        if (pixelArray[i][j].color == Blue)
        {
            conBlue++;

            if (pixelArray[i++][j].color != Blue && pixelArray[i][j++].color != Blue && pixelArray[i][j--].color != Blue && pixelArray[i--][j].color != Blue)
            {
                conBlue = 0;
            }
        
            if (conBlue > totalConBlue)
            {
                totalConBlue = conBlue;
            }
        }
    }
}

Source: Windows Questions C++

LEAVE A COMMENT