Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 050c398

Browse files
Chapter 05 section 08 codes udpated.
1 parent 8ff339a commit 050c398

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

‎05-Maze-Solver/08-BFS-Maze-Solver/src/AlgoVisualizer.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ private void run(){
3535
LinkedList<Position> queue = new LinkedList<Position>();
3636
Position entrance = new Position(data.getEntranceX(), data.getEntranceY());
3737
queue.addLast(entrance);
38-
data.visited[entrance.x][entrance.y] = true;
38+
data.visited[entrance.getX()][entrance.getY()] = true;
3939

4040
boolean isSolved = false;
4141

4242
while(queue.size() != 0){
43-
Position curPos = queue.removeFirst();
44-
setData(curPos.x, curPos.y, true);
43+
Position curPos = queue.pop();
44+
setData(curPos.getX(), curPos.getY(), true);
4545

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

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

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

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

‎05-Maze-Solver/08-BFS-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‎

105 KB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /