(int n)
| 19 | |
| 20 | // creates n-by-n grid, with all sites initially blocked |
| 21 | public Percolation(int n) { |
| 22 | if (n <= 0) throw new IllegalArgumentException("n should be larger than 0"); |
| 23 | gridSize = n; |
| 24 | uf1 = new WeightedQuickUnionUF(n * n + 1); |
| 25 | uf2 = new WeightedQuickUnionUF(n * n + 2); |
| 26 | sites = new boolean[n * n + 2]; |
| 27 | sites[0] = true; // uf1's top and uf2's top |
| 28 | sites[n * n + 1] = true; // uf2's bottom |
| 29 | numOfOpenSites = 0; |
| 30 | } |
| 31 | |
| 32 | // calculate index for row col |
| 33 | private int getSite(int row, int col) { |
nothing calls this directly
no outgoing calls
no test coverage detected