Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Recursion FindPath[solved]

 
David Delgado
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved, thank you!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hard to say what's happening without seeing the canFlowOffMap method.
 
David Delgado
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry,

Actually it was meant to be canFindPath (I changed name). I'm making recursive calls to itself.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest may be to replace "canFindPath(...)" by "if (canFindPath(...)) return true" or something like that.
 
David Delgado
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Uff, that solved my problem.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd go further and ask you not to edit any post that has been replied to, because of the same reason.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, I feel like I helped someone who was not supposed to ask for help with his homework.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic