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

Method open

LabEnv/01Lab/Percolation.java:49–67  ·  view source on GitHub ↗
(int row, int col)

Source from the content-addressed store, hash-verified

47
48 // opens the site (row, col) if it is not open already
49 public void open(int row, int col) {
50 validate(row, "row");
51 validate(col, "col");
52 if (!isOpen(row, col)) {
53 numOfOpenSites++;
54 sites[getSite(row, col)] = true;
55 for (int i = 0; i < dirs.length; i++) {
56 int neightborRow = row + dirs[i][0];
57 int neightborCol = col + dirs[i][1];
58 if (neightborRow == gridSize + 1)
59 uf2.union(getSite(neightborRow, neightborCol), getSite(row, col));
60 if (neightborRow == 0 || isInGrid(neightborRow, neightborCol) && isOpen(
61 neightborRow, neightborCol)) {
62 uf1.union(getSite(neightborRow, neightborCol), getSite(row, col));
63 uf2.union(getSite(neightborRow, neightborCol), getSite(row, col));
64 }
65 }
66 }
67 }
68
69 // is the site (row, col) open?
70 public boolean isOpen(int row, int col) {

Callers 4

mainMethod · 0.95
PercolationStatsMethod · 0.95
mainMethod · 0.95
mainMethod · 0.95

Calls 4

validateMethod · 0.95
isOpenMethod · 0.95
getSiteMethod · 0.95
isInGridMethod · 0.95

Tested by

no test coverage detected