0

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.

Edited by johans22

2
Contributors
4
Replies
23
Views
2 Years
Discussion Span
Last Post by johans22
0

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);
}
0
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;
    }

Edited by johans22

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.