Wednesday, November 12, 2008

Tower of Hanoi





Code from: http://weblogs.java.net/blog/mortazavi/archive/2005/08/recursive_progr.html

private void moveTower (int numDisks, int start, int end, int temp)
{
if (numDisks == 1)
moveOneDisk (start, end);

else
{
moveTower (numDisks-1, start, temp, end);
moveOneDisk (start, end);
moveTower (numDisks-1, temp, end, start);
}
}

No comments: