Why doesn't this works?

Whenever I call that function again, b.is_clustered[coor_x][coor_y] always returns to 0 even though it is changed to 1 in the function. What should I do to keep b.is_clustered to 1? Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void seek_for_cluster (board b, int color, int coor_x, int coor_y, int cluster_n)
{
if (b.is_clustered[coor_x][coor_y]==0)
{
if (b.color[coor_x][coor_y]==color)
{
b.is_clustered[coor_x][coor_y]=1;
b.cluster_n[coor_x][coor_y]=cluster_n;
if (coor_x>0) seek_for_cluster (b, color, coor_x-1, coor_y, cluster_n);
if (coor_y>0) seek_for_cluster (b, color, coor_x, coor_y-1, cluster_n);
if (coor_x<size_x-1) seek_for_cluster (b, color, coor_x+1, coor_y, cluster_n);
if (coor_y<size_y-1) seek_for_cluster (b, color, coor_x, coor_y+1, cluster_n);
}
}
}
You're passing the board by value, so you change is_clustered only for that copy.
Pass by reference instead.
How do I do that?

Edit: I found it on another website. Thanks!
Last edited on
Topic archived. No new replies allowed.