Link to home
Start Free TrialLog in
Avatar of PCurd
PCurd

asked on

Algorithm to remove cells of an array that are the same and connected needed please!

Hi!

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:

0000001
1001010
1010110
1110101

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

1000000
1110000
0011000
0110000

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!!

-
Peter

ASKER CERTIFIED SOLUTION
Avatar of billious
billious

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PCurd
PCurd

ASKER

I had to make a few changes and mostly recoded "analyse" but it was extremely useful :-D

Thank you for your quick response and very helpful code!

-
Peter