I need to write a a method in my code that can take a two dimensional array and return how many different groups there are within the array. A group is defined as, "all cells connected directly to other cells in the up/down/left/right (not diagonal) directions" where a cell in the array would be represented by an asterisk. I need to write a method that iterates through the entire array that also calls a recursive method that changes every asterisk into a letter that is unique to that group. For example this is a sample input:
char image[][] = {
{'*','*',' ',' ',' ',' ',' ',' ','*',' '},
{' ','*',' ',' ',' ',' ',' ',' ','*',' '},
{' ',' ',' ',' ',' ',' ','*','*',' ',' '},
{' ','*',' ',' ','*','*','*',' ',' ',' '},
{' ','*','*',' ','*',' ','*',' ','*',' '},
{' ','*','*',' ','*','*','*','*','*','*'},
{' ',' ',' ',' ',' ',' ',' ',' ','*',' '},
{' ',' ',' ',' ',' ',' ',' ',' ','*',' '},
{' ',' ',' ','*','*','*',' ',' ','*',' '},
{' ',' ',' ',' ',' ','*',' ',' ','*',' '}};
and the output would be something like this:
aa b
a b
cc
d ccc
dd c c c
dd cccccc
c
c
eee c
e c
I mostly need help with the method that iterates through the given image because I don't know how to make the code distinguish between the groups.