Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Other Web Development Languages (http://www.programmingforums.org/forum40.html)
-   -   Recursive Function For Testing A Connection? (http://www.programmingforums.org/showthread.php?t=9677)

Sane May 6th, 2006 11:32 AM

Recursive Function For Testing A Connection?
 
I have a two dimensional grid, and need to test if any given point on the grid is connected to any side of the grid, through any other combination of points. Would a recursive function be the best way to do this? If so, how would I do that without ending up with infinite recursion?

If recursion isn't the best option, my other thought was some straight loops, but I'm getting tired of that crap. :(


Edit: Wrong forum. I meant to put this in "Other Scripting Languages", not "Other Web Development". Move please. :o

Ooble May 6th, 2006 1:03 PM

I think recursion would be the best way to go about this, as you say. To avoid infinite recursion, which I presume would occur when connections loop back on themselves, just log where you've been.

This sounds like fun. Time to break out Python.

Sane May 6th, 2006 6:35 PM

All right. I took a buddy's suggestion and just did iteration from bottom left to top right. Any point that's connected to a wall is deemed connected, and any point that's connected to a point deemed connected... is connected. Then an outside loop goes around that to work itself backwards, and bingo. It worked perfectly. I don't think recursion would have worked as well in this instance.

Ooble May 6th, 2006 6:44 PM

Makes sense to me. I didn't realise "connected" was defined as being attached to a wall - should've re-read your post. For some reason, I thought you wanted a function to check if a node was connected to another node.

DaWei May 6th, 2006 7:15 PM

I thought you meant Beej-y connections. Go to your room. I get your dessert.


All times are GMT -5. The time now is 7:39 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC