class19-Recursion.java

Moveg numdiscs 1 other dest source public

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: e); Recursion.placeOnTop(g, dest, length); } public static int removeTop(Grid g, int tower) { int col; col = tower * 8; int row; for (row = 0; row < 7; row = row + 1) { if (g.getColor(new Location(row, col)).getRed() == 255) { int length; length = 0; while (g.getColor(new Location(row, col)).getRed() == 255) { g.setColor(new Location(row, col), new Color(0, 0, 0)); col = col + 1; length = length + 1; } return length; } } throw new RuntimeException("Should not get here"); } public static void placeOnTop(Grid g, int tower, int length) { int col; col = tower * 8; int row; for (row = 6; row >= 0; row = row - 1) { if (g.getColor(new Location(row, col)).getRed() == 0) { while (length > 0) { g.setColor(new Location(row, col), new Color(255, 255, 255)); col = col + 1; length = length - 1; } return; } } throw new RuntimeException("Should not get here"); } public static void testHanoi() { Grid g; g = new Grid(7, 23); g.setTitle("Towers...
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