Algorithm to remove cells of an array that are the same and connected needed please!
Posted on 2003-03-08
I have an array[0..7,0..15] of what for the purpose of this can be assumed to be 1's and 0's. They will be arranged in random patterns, for example:
etc and I'm going to get the location of a cell and have to identify all cells that have the same value in them and also are connected somehow to it. For example
contains one whole group as each cell is connected to another of the same value.
Basically I'm finding groups of either 1's or 0's given a cell to start from.
I've tried the following algorithm start but run out of ideas:
make a copy of array
remove from copy array anything not same value
remove items with no connection to any other (isolated values)
leaves a series of groups
identify group cell is in
go systematically through the group marking each cell on the original array.
My problem is the "systematically" bit.. I've tried thinking of recursion and think that's the right track but I really can't write one that works.. Help anyone? please?
I'm also running on a deadline (This is about the only thing that I have left to finish on the program) so any code would be gratefully received!!