aspose file tools*
The moose likes Beginning Java and the fly likes Recursion FindPath[solved] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Recursion FindPath[solved]" Watch "Recursion FindPath[solved]" New topic
Author

Recursion FindPath[solved]

David Delgado
Greenhorn

Joined: Sep 19, 2010
Posts: 6
Solved, thank you!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41526
    
  53
Hard to say what's happening without seeing the canFlowOffMap method.


Ping & DNS - my free Android networking tools app
David Delgado
Greenhorn

Joined: Sep 19, 2010
Posts: 6
Sorry,

Actually it was meant to be canFindPath (I changed name). I'm making recursive calls to itself.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41526
    
  53
If any of the recursive calls ever return "true", then you should not recurse any further, but return straight back up the call stack. As it is, you're ignoring the returned value, and continue to look for solutions in other directions.
David Delgado
Greenhorn

Joined: Sep 19, 2010
Posts: 6
Thank you for replying. So then I need to put if statements inside my check N/W/S/E loops to check if the program returned true?? That's what I was thinking of earlier this morning but wasn't sure. Should I use a local variable to keep track of the boolean?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41526
    
  53
The easiest may be to replace "canFindPath(...)" by "if (canFindPath(...)) return true" or something like that.
David Delgado
Greenhorn

Joined: Sep 19, 2010
Posts: 6
Thank you Uff, that solved my problem.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
Don't go and edit your first post

Now people who read this thread can't understand what the question was about, and the replies all read as nonsense.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

I'd go further and ask you not to edit any post that has been replied to, because of the same reason.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41526
    
  53
Indeed, I feel like I helped someone who was not supposed to ask for help with his homework.
 
jQuery in Action, 2nd edition
 
subject: Recursion FindPath[solved]