@Test public void testMove() { tower.move(3, 0, 2); List<Peg<Disk>> pegs = tower.pegs(); Assert.assertEquals(3, pegs.size()); Assert.assertEquals(3, pegs.get(2).size()); Assert.assertEquals(0, pegs.get(0).size()); Assert.assertEquals(0, pegs.get(1).size()); }
public void move(int numDisks, int fromPeg, int toPeg) { if (numDisks == 1) { move(fromPeg, toPeg); } else { move(numDisks - 1, fromPeg, sparePeg(fromPeg, toPeg)); move(fromPeg, toPeg); move(numDisks - 1, sparePeg(fromPeg, toPeg), toPeg); } }
TowerOfHanoi { public void move(int numDisks, int fromPeg, int toPeg) { if (numDisks == 1) { move(fromPeg, toPeg); } else { move(numDisks - 1, fromPeg, sparePeg(fromPeg, toPeg)); move(fromPeg, toPeg); move(numDisks - 1, sparePeg(fromPeg, toPeg), toPeg); } } }
TowerOfHanoi { public void move(int numDisks, int fromPeg, int toPeg) { if (numDisks == 1) { move(fromPeg, toPeg); } else { move(numDisks - 1, fromPeg, sparePeg(fromPeg, toPeg)); move(fromPeg, toPeg); move(numDisks - 1, sparePeg(fromPeg, toPeg), toPeg); } } TowerOfHanoi(int numPegs, int numDisks); }
TowerOfHanoi { public void move(int numDisks, int fromPeg, int toPeg) { if (numDisks == 1) { move(fromPeg, toPeg); } else { move(numDisks - 1, fromPeg, sparePeg(fromPeg, toPeg)); move(fromPeg, toPeg); move(numDisks - 1, sparePeg(fromPeg, toPeg), toPeg); } } TowerOfHanoi(int numPegs, int numDisks); List<Peg<Disk>> pegs(); void move(int numDisks, int fromPeg, int toPeg); }
TowerOfHanoi { public void move(int numDisks, int fromPeg, int toPeg) { if (numDisks == 1) { move(fromPeg, toPeg); } else { move(numDisks - 1, fromPeg, sparePeg(fromPeg, toPeg)); move(fromPeg, toPeg); move(numDisks - 1, sparePeg(fromPeg, toPeg), toPeg); } } TowerOfHanoi(int numPegs, int numDisks); List<Peg<Disk>> pegs(); void move(int numDisks, int fromPeg, int toPeg); static final Logger LOGGER; }