



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: DATA STRUC/ALGORITHMS; Subject: COMPUTER PROGRAMMING; University: University of Florida; Term: Fall 2008;
Typology: Assignments
1 / 5
This page cannot be seen from the preview
Don't miss anything!




package dataStructures;
import java.util.Vector;
public class RatInMaze {
int [][] maze_;
int width_; int height_;
ArrayStack stack_; //You must use this variable to ref your stack ArrayQueue queue_; //You must use this variable to ref your queue
output += "'ve traveled through " + traveled_ + "square(s). The path contains " + pathLength_ + "square(s)"; System.out.println(output); } else { System.out.println("I cannot get there."); }
public boolean searchStack( int fromX,int fromY,int toX,int toY) { stack_= new ArrayStack(); queue_ = null ; //Your code goes here. } public boolean searchStackSmart( int fromX,int fromY,int toX,int toY) { stack_= new ArrayStack(); queue_ = null ; //Your code goes here. } public boolean searchQueue( int fromX,int fromY,int toX,int toY) { stack_= null ; queue_ = new ArrayQueue(); //Your code goes here. }
// Please use the test code as follows. public static void main(String[] args) { RatInMaze rim = new RatInMaze(); Vector
maze.add("000100000010000"); maze.add("000100100000000"); maze.add("000000011111111"); maze.add("000111001001000"); maze.add("000001100100100"); maze.add("110001100100000"); maze.add("011001100100000"); maze.add("001001100100000"); maze.add("011001000000000"); maze.add("001000111111111"); maze.add("001010000000000"); maze.add("001010001000000"); maze.add("000010010000000");
System.out.println("\n\n");
rim.load(maze); rim.print(rim.searchQueue(-1,1,10,10)); rim.load(maze);
rim.print(rim.searchStack(0,0,41,1));
int fromX = 0; int fromY = 7; int toX = 14; int toY = 6; System.out.println("\n\n"); rim.load(maze); System.out.println("A rat is searching:"); rim.print(rim.searchStack(fromX,fromY,toX,toY));
System.out.println("\n\n"); rim.load(maze); System.out.println("Multiple rats are searching:"); rim.print(rim.searchQueue(fromX,fromY,toX,toY));
System.out.println("\n\n"); rim.load(maze); System.out.println("A smart rat is searching:"); rim.print(rim.searchStackSmart(fromX,fromY,toX,toY));