Sign in to follow this  

Puzzle grid recursion ( infinite recusion errors )...

This topic is 4099 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I have run into a wall with my current project( been working on a solution the past couple of days ) dealing with recursion. I have researched tuts on the web, but they are either all to easy, or to complex. I am trying to search through a 2D array of structs, for like values ( of the structs members ). Basicly, I am trying to 'link' structs together based on shared values ( in this case colors ). I have written and re-written hack-code, but am looking for way to clean it up using controlled recursion... Any ideas? ahayweh

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If it's just a 2d array, it's probably simpler to express as an iteration. You have to traverse the array once for every element in it. So flatten the array and traverse it once for each element (but don't link structs to themselves!), in pseudo-python:


for struct1 in flat_struct_array:
for struct2 in flat_struct_array:
if (not struct1 == struct2) and shared_values(struct1, struct2):
link(struct1, struct2)

Share this post


Link to post
Share on other sites
Hey guys,

Thanks for the input. I switched to iterative processing, and was able to fix the problem. I guess I was looking to recursion as a more sophisticated way of solving it, but at this point, I just want to get through this block of code. Alright, thanks again.

Share this post


Link to post
Share on other sites
Depending on the number of objects and distinct classes, it might be best to do something more like this:
Hashtable<paramType,List<myObject>> stuff = new Hashtable();

foreach(myObject obj in mainList){
List<myObject> list = stuff[obj.param];
if(list == null) list = stuff[obj.param] = new List<myObject>();
list.add(obj);
}

foreach(List<myObject> list in stuff){
// ... link all items in this list
}

Share this post


Link to post
Share on other sites
Are you trying to link structs only for like colors in an area or across the whole pixel set?

eg: 2 blobs of blue seperate by green
> 3 lists
where two lists of blue blobs and the green
or
> 2 lists
where the blue blobs are connected in a single list + green list

Share this post


Link to post
Share on other sites

This topic is 4099 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this