File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
week4/priority-queues/assignment-8-puzzle Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1+ import edu .princeton .cs .algs4 .StdOut ;
2+
13public class Board {
24 int [][] tiles ;
35
@@ -9,7 +11,18 @@ public Board(int[][] tiles) {
911
1012 // string representation of this board
1113 public String toString () {
12- return "" ;
14+ String s = new String ();
15+
16+ s = s .concat (dimension () + "\n " );
17+
18+ for (int i = 0 ; i < dimension (); i ++) {
19+ for (int j = 0 ; j < dimension (); j ++) {
20+ s = s .concat (" " + tiles [i ][j ]);
21+ }
22+ s = s .concat ("\n " );
23+ }
24+
25+ return s ;
1326 }
1427
1528 // board dimension n
Original file line number Diff line number Diff line change @@ -33,8 +33,9 @@ public static void main(String[] args) {
3333 int n = in .readInt ();
3434 int [][] tiles = new int [n ][n ];
3535 for (int i = 0 ; i < n ; i ++)
36- for (int j = 0 ; j < n ; j ++)
37- tiles [i ][j ] = in .readInt ();
36+ for (int j = 0 ; j < n ; j ++) {
37+ tiles [i ][j ] = in .readInt ();
38+ }
3839
3940 Board initial = new Board (tiles );
4041
You can’t perform that action at this time.
0 commit comments