Skip to content

Commit 68f1f3e

Browse files
committed
Chapter 06 codes updated.
1 parent 9447475 commit 68f1f3e

File tree

61 files changed

+2828
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2828
-12
lines changed

06-Maze-Generalization/04-Non-Recursive-DFS-Maze-Generalization/src/AlgoVisualizer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ private void run(){
4545
int newX = curPos.getX() + d[i][0]*2;
4646
int newY = curPos.getY() + d[i][1]*2;
4747

48-
if(data.inArea(newX, newY)
49-
&& !data.visited[newX][newY]
50-
&& data.maze[newX][newY] == MazeData.ROAD){
48+
if(data.inArea(newX, newY) && !data.visited[newX][newY]){
5149
stack.push(new Position(newX, newY));
5250
data.visited[newX][newY] = true;
5351
setData(curPos.getX() + d[i][0], curPos.getY() + d[i][1]);

06-Maze-Generalization/05-BFS-Maze-Generalization/src/AlgoVisualizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class AlgoVisualizer {
88

9-
private static int DELAY = 20;
9+
private static int DELAY = 5;
1010
private static int blockSide = 8;
1111

1212
private MazeData data;

06-Maze-Generalization/06-Random-Maze-Generalization/src/RandomQueue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void add(E e){
1414

1515
public E remove(){
1616
if(queue.size() == 0)
17-
throw new IllegalArgumentException("There's no element to remove in Random Qeuue");
17+
throw new IllegalArgumentException("There's no element to remove in Random Queue");
1818

1919
int randIndex = (int)(Math.random()*queue.size());
2020

06-Maze-Generalization/07-Random-Maze-Generalization-with-Mist/src/AlgoVisualizer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import javafx.geometry.Pos;
2-
3-
import java.util.LinkedList;
4-
import java.util.Stack;
51
import java.awt.*;
62

73
public class AlgoVisualizer {
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ private void run(){
4545
int newX = curPos.getX() + d[i][0]*2;
4646
int newY = curPos.getY() + d[i][1]*2;
4747

48-
if(data.inArea(newX, newY)
49-
&& !data.visited[newX][newY]
50-
&& data.maze[newX][newY] == MazeData.ROAD){
48+
if(data.inArea(newX, newY) && !data.visited[newX][newY]){
5149
queue.add(new Position(newX, newY));
5250
data.visited[newX][newY] = true;
5351
data.openMist(newX, newY);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.ArrayList;
2+
3+
public class RandomQueue<E>{
4+
5+
private ArrayList<E> queue;
6+
7+
public RandomQueue(){
8+
queue = new ArrayList<E>();
9+
}
10+
11+
public void add(E e){
12+
queue.add(e);
13+
}
14+
15+
public E remove(){
16+
if(queue.size() == 0)
17+
throw new IllegalArgumentException("There's no element to remove in Random Qeuue");
18+
19+
int randIndex = (int)(Math.random()*queue.size());
20+
21+
E randElement = queue.get(randIndex);
22+
queue.set(randIndex, queue.get(queue.size()-1));
23+
queue.remove(queue.size()-1);
24+
25+
return randElement;
26+
}
27+
28+
public int size(){
29+
return queue.size();
30+
}
31+
32+
public boolean empty(){
33+
return size() == 0;
34+
}
35+
}

0 commit comments

Comments
 (0)