Got an array 350x550 of type integer. There are groups of connected or single elements with value 7 in some areas of the array. I need a c or c++ code that identifies each group or element and returns each group's total element(s) plus location of each element in the array using recursion or preferably iteration.

The link is an exceelent source.
I was wondered, how is this done most fficienly using recursion?.

class Elements;
{
   int total;
   int x;
   int y;
}

Elements floodfill(x, y, w, h, newval)
{
.
.
.
Elements Group1=GetElements(x + 1, y, w, h, newval);
Elements Group1=GetElements(x - 1, y, w, h, newval);
Elements Group1=GetElements(x,  y + 1, w, h, newval);
Elements Group1=GetElements(x,  y - 1, w, h, newval);
}
this is closer. Using recursion in here is not easy. ISO code that runs trouble free.


    class Elements;
    {
    int total;
    int *x;
    int *y;
    }
    Elements floodfill(x, y, w, h, newval)
    {
    .
    .
    .
    Elements Group1=GetElements(x + 1, y, w, h, newval);
    Elements Group2=GetElements(x - 1, y, w, h, newval);
    Elements Group3=GetElements(x, y + 1, w, h, newval);
    Elements Group4=GetElements(x, y - 1, w, h, newval);
    // combine Group1 .. Group4 into Group
    return Group;
    }

Any ideas?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.