public class TowersOfHanoi extends Object
Modifier and Type | Class and Description |
---|---|
static class |
TowersOfHanoi.Move
The Move class represents the action of moving one disc between pegs.
|
Constructor and Description |
---|
TowersOfHanoi() |
Modifier and Type | Method and Description |
---|---|
static void |
iterativeHanoi(int disc,
int from,
int aux,
int to)
Iterative solution using stack.
|
static void |
main(String[] args) |
(package private) static void |
move(int disc,
int source,
int dest)
Method to report and move a disc.
|
static void |
recursiveHanoi(int disc,
int from,
int aux,
int to)
The recursive solution for Towers of Hanoi.
|
public static void main(String[] args) throws InterruptedException
InterruptedException
public static void recursiveHanoi(int disc, int from, int aux, int to)
move(int, int, int)
the requested disc to the destination pole.
disc
- the disc you are moving to the destination (auxiliary) pole.from
- the pole that the disk is currently onaux
- the auxiliary pole (provides supplementary or additional help) but won't be used to move this disk
at this point of time.to
- the pole that the disk will move topublic static void iterativeHanoi(int disc, int from, int aux, int to)
disc
- the current discfrom
- what pole the disc is onaux
- the auxiliary poleto
- what pole the disc is being moved tostatic void move(int disc, int source, int dest)
disc
- the current discsource
- the pole the disc is ondest
- the pole the disc is being moved to