diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-03-05 13:41:02 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2013-11-15 17:38:32 +0100 |
commit | 7ceb4cb342b5d9b90b89edebe02ed8f03dd73115 (patch) | |
tree | 08e6acf25f995f818f01d98179bc03987d663d1b /Algorithms/Part-I/1-Percolation/Percolation.java | |
parent | e372893b90da7b0e68741f5e74a984bdbcf6cc2f (diff) | |
download | coursera-7ceb4cb342b5d9b90b89edebe02ed8f03dd73115.zip coursera-7ceb4cb342b5d9b90b89edebe02ed8f03dd73115.tar.gz |
Algorithms-I : 1-Percolation: I stupidly inverted (i,j) coordinates
Diffstat (limited to 'Algorithms/Part-I/1-Percolation/Percolation.java')
-rw-r--r-- | Algorithms/Part-I/1-Percolation/Percolation.java | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/Algorithms/Part-I/1-Percolation/Percolation.java b/Algorithms/Part-I/1-Percolation/Percolation.java index 1c2567e..8364585 100644 --- a/Algorithms/Part-I/1-Percolation/Percolation.java +++ b/Algorithms/Part-I/1-Percolation/Percolation.java @@ -22,17 +22,17 @@ public class Percolation { if (i < 1 || j < 1 || i > N || j > N) throw new java.lang.IndexOutOfBoundsException("check your indexes"); - int x = (j-1)*N+i; + int x = (i-1)*N+j; if (opened[x]) return; opened[x] = true; - if (i > 1 && opened[x-1]) uf.union(x, x-1); - if (i < N && opened[x+1]) uf.union(x, x+1); - if (j == 1) { - uf.union(x, 0); + if (j > 1 && opened[x-1]) uf.union(x, x-1); + if (j < N && opened[x+1]) uf.union(x, x+1); + if (i == 1) { + uf.union(0, x); if (opened[x+N]) uf.union(x, x+N); } - else if (j == N) { - uf.union(x, N*N+1); + else if (i == N) { + uf.union(N*N+1, x); if (opened[x-N]) uf.union(x, x-N); } else { if (opened[x-N]) uf.union(x, x-N); @@ -45,7 +45,7 @@ public class Percolation { if (i < 1 || j < 1 || i > N || j > N) throw new java.lang.IndexOutOfBoundsException("check your indexes"); - return opened[(j-1)*N+i]; + return opened[(i-1)*N+j]; } // is site (row i, column j) full? @@ -53,7 +53,7 @@ public class Percolation { if (i < 1 || j < 1 || i > N || j > N) throw new java.lang.IndexOutOfBoundsException("check your indexes"); - int x = (j-1)*N+i; + int x = (i-1)*N+j; return ((opened[x]) && (uf.find(x) == 0)); } |