11-08 Class Notes CS 107

11-08 Class Notes CS 107 - See web site for description of...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: See web site for description of program #5- Announcements: Questions? Prof. John Lillis went through an example of using arrays in Java- Last Time: Discussion of program #5- Finish the maze example- Today: Program #5 Remember how far we had gotten with version Maze 3 on 10/29. We had added the cameFrom array to prevent us from going back and forth between two squares.- /** * Class Maze3 illustrates navigating a maze. * An important change here is that the 2-dimensional array is represented * in one dimension, which makes it easier to write some parts of the code. To * move to a different square we now only need to add a single number to the * current square. The order of attempted moves is changed to be left, up, Maze Traversal 11-08 Class Notes CS 107 Monday, November 08, 2010 2:01 PM 107 Fall 2010 Page 1 * right, down. * This version still does not solve the problems of stopping once the * solution is found, or preventing an infinite loop of moving between two * squares. * * Running the program gives: 11, 12, 11, 12, 11, 12, 11, ...(keeps repeating until you get: )... 11, 12, 11, Exception in thread "main" java.lang.StackOverflowError * * Problems: * Bounces between two moves, doesn't stop at end, doesn't display solution */ public class Maze3 { private static int start = 11; // this is static so main() can use it private static int end = 88; // this is static so main() can use it private int maze = { /* 0 1 2 3 4 5 6 7 8 9 */ /* 0 */ 1,1,1,1,1,1,1,1,1,1, /*10 */ 1,0,0,0,1,1,1,1,1,1, /*20 */ 1,1,0,1,1,1,0,0,1,1, /*30 */...
View Full Document

Page1 / 5

11-08 Class Notes CS 107 - See web site for description of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online