Skip to content

Commit 8ff339a

Browse files
committedSep 5, 2017
Chapter 05 section 06-07 codes updated.
1 parent 1baca8c commit 8ff339a

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed
 

‎05-Maze-Solver/06-Non-Recursive-DFS-Maze-Solver/src/AlgoVisualizer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ public void run(){
3434
Stack<Position> stack = new Stack<Position>();
3535
Position entrance = new Position(data.getEntranceX(), data.getEntranceY());
3636
stack.push(entrance);
37-
data.visited[entrance.x][entrance.y] = true;
37+
data.visited[entrance.getX()][entrance.getY()] = true;
3838

3939
while(!stack.empty()){
4040
Position curPos = stack.pop();
41-
setData(curPos.x, curPos.y, true);
41+
setData(curPos.getX(), curPos.getY(), true);
4242

43-
if(curPos.x == data.getExitX() && curPos.y == data.getExitY())
43+
if(curPos.getX() == data.getExitX() && curPos.getY() == data.getExitY())
4444
break;
4545

4646
for(int i = 0 ; i < 4 ; i ++){
47-
int newX = curPos.x + d[i][0];
48-
int newY = curPos.y + d[i][1];
47+
int newX = curPos.getX() + d[i][0];
48+
int newY = curPos.getY() + d[i][1];
4949

5050
if(data.inArea(newX, newY)
5151
&& !data.visited[newX][newY]
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
public class Position {
22

3-
public int x, y;
3+
private int x, y;
44

55
public Position(int x, int y){
66
this.x = x;
77
this.y = y;
88
}
9+
10+
public int getX(){return x;}
11+
public int getY(){return y;}
912
}

‎05-Maze-Solver/07-More-about-Non-Recursive-DFS-Maze-Solver/src/AlgoVisualizer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ private void run(){
3434
Stack<Position> stack = new Stack<Position>();
3535
Position entrance = new Position(data.getEntranceX(), data.getEntranceY());
3636
stack.push(entrance);
37-
data.visited[entrance.x][entrance.y] = true;
37+
data.visited[entrance.getX()][entrance.getY()] = true;
3838

3939
boolean isSolved = false;
4040

4141
while(!stack.empty()){
4242
Position curPos = stack.pop();
43-
setData(curPos.x, curPos.y, true);
43+
setData(curPos.getX(), curPos.getY(), true);
4444

45-
if(curPos.x == data.getExitX() && curPos.y == data.getExitY()){
45+
if(curPos.getX() == data.getExitX() && curPos.getY() == data.getExitY()){
4646
isSolved = true;
4747
findPath(curPos);
4848
break;
4949
}
5050

5151
for(int i = 0 ; i < 4 ; i ++){
52-
int newX = curPos.x + d[i][0];
53-
int newY = curPos.y + d[i][1];
52+
int newX = curPos.getX() + d[i][0];
53+
int newY = curPos.getY() + d[i][1];
5454

5555
if(data.inArea(newX, newY)
5656
&& !data.visited[newX][newY]
@@ -72,8 +72,8 @@ private void findPath(Position des){
7272

7373
Position cur = des;
7474
while(cur != null){
75-
data.result[cur.x][cur.y] = true;
76-
cur = cur.prev;
75+
data.result[cur.getX()][cur.getY()] = true;
76+
cur = cur.getPrev();
7777
}
7878
}
7979

‎05-Maze-Solver/07-More-about-Non-Recursive-DFS-Maze-Solver/src/Position.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
public class Position {
22

3-
public int x, y;
4-
public Position prev;
3+
private int x, y;
4+
private Position prev;
55

66
public Position(int x, int y, Position prev){
77
this.x = x;
@@ -12,4 +12,8 @@ public Position(int x, int y, Position prev){
1212
public Position(int x, int y){
1313
this(x, y, null);
1414
}
15+
16+
public int getX(){return x;}
17+
public int getY(){return y;}
18+
public Position getPrev(){return prev;}
1519
}

‎05-Maze-Solver/Chapter-05.key

389 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.