class19-Recursion.java

Class19 recursionjava

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public class Recursion { public static void moveToWall() { if (Robot.frontIsClear()) { Robot.move(); Recursion.moveToWall(); } } public static int fact(int n) { if (n == 0) { return 1; } else { return n * Recursion.fact(n - 1); } } public static void move(Grid g, int numDiscs, int source, int dest, int other) { if (numDiscs > 0) { //MOVE ALL BUT ONE DISC FROM SOURCE TO OTHER Recursion.move(g, numDiscs - 1, source, other, dest); //MOVE ONE DISC FROM SOURCE TO DEST Recursion.moveOneDisc(g, source, dest); Recursion.waitForKeyPress(g); //MOVE ALL BUT ONE DISC FROM OTHER TO DEST Recursion.move(g, numDiscs - 1, other, dest, source); } } public static void moveOneDisc(Grid g, int source, int dest) { int length; length = Recursion.removeTop(g, sourc...
View Full Document

This note was uploaded on 09/14/2010 for the course CS 15-100 taught by Professor Dave during the Spring '08 term at Carnegie Mellon.

Ask a homework question - tutors are online