Java Reference
In-Depth Information
ȗ
BEFORE_LARGEST
: The helper mover moves the smaller pile to
the other peg.
ȗ
LARGEST
: Move the largest disk from the source to the destination.
ȗ
AFTER_LARGEST
: The helper mover moves the smaller pile from
the other peg to the target.
ȗ
DONE
: All moves are done.
Test your program as follows:
DiskMover mover = new DiskMover(1, 3, n);
while (mover.hasMoreMoves())
System.out.println(mover.nextMove());
Exercise P13.14. Escaping a Maze. You are currently located inside a
maze. The walls of the maze are indicated by asterisks (*).
Use the following recursive approach to check whether you can escape
from the maze: If you are at an exit, return
true
. Recursively check
whether you can escape from one of the empty neighboring locations
without visiting the current location. This method merely tests whether
there is a path out of the maze. Extra credit if you can print out a path
that leads to an exit.
G Exercise P13.15. The Koch Snowflake. A snowflake-like shape is
recursively defined as follows. Start with an equilateral triangle:
Next, increase the size by a factor of three and replace each straight
line with four line segments.
623