Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maze Solving

 
tyler naughton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm having trouble with my current program here. We are supposed to find a path out of a maze using a coordinate class. We have to create coordinates and then push them onto a stack. At the end we have to pop the stack to get the path coordinates. I am having problems backtracking in my while loop. I can get all the way to that but when it hits a dead end I can't figure out how to pop the stack and take the coordinates from the previous space and apply them to the loop. If anybody could help me out that would be great. I have included the coordinate class as well as some sample mazes. Thanks.

I think the problem is in this while loop (line 152)

Program Maze....

Coordinate class...


DynamicStack class
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a lot of code to go through and in all fairness I haven't. But I have a remark:

Do not catch ArrayIndexOutOfBoundsExceptions. Just ask the size of the array and operate in those bounds.
And if you really really really want to catch it then at least log it, otherwise you'll never know about the exception.
 
Wim Vanni
Ranch Hand
Posts: 96
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the class DynamicStack you declare 'head' to be of type 'Node'. What class is this 'Node'? You didn't add one to your code ..

Wim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic