Hey guys I had an assignment to recursively write the Towers of Hanoi then test it.
I did not have too much of an issue getting the program written
But I am not sure what the book means by test the efficiency
do they want the number of moves my program makes, or do they want the time it takes to run. And how do I get either one?
help is appreciated
import TerminalIO.KeyboardReader;
public class towers
{
public static void main(String[] args)
{
KeyboardReader reader = new KeyboardReader();
int numberofRings = reader.readInt("Enter number of Rings: ");
move (numberofRings, 1, 3, 2);
}
static void move(int n, int i, int j, int k)
{
if (n > 0)
{
move(n - 1, i, k, j);
System.out.println("Move ring " + n + "from peg" + i + "to" + j);
move(n - 1, k, j, i);
}
}
}