MCPcopy Create free account
hub / github.com/MolinDeng/Princeton-algs4 / Percolation

Method Percolation

01Lab-Percolation/Percolation.java:21–30  ·  view source on GitHub ↗
(int n)

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected