Link to code: PercolationUF.java
/**
* Simulate a system to see its Percolation Threshold, but use
* a UnionFind implementation to determine whether simulation
* occurs. The main idea is that initially all cells of a simulated
* grid are each part of their own set so that there will be n^2 sets
* in an nxn simulated grid. Finding an open cell will connect the
* cell being marked to its neighbors --- this means that the set
* in which the open cell is 'found' will be unioned with the sets of
* each neighboring cell. The union/find implementation supports
* the 'find' and 'union' typical of UF algorithms.
* <P>
* @author Owen Astrachan
* @author Jeff Forbes
*
*/
public class PercolationUF implements IPercolate {
private final int OUT_BOUNDS = -1;
public PercolationUF(int n, IUnionFind unionThing){
// TODO complete PercolationUF constructor
}
/**
* Return an index that uniquely identifies (row,col), typically
* an index based on row-major ordering of cells in a two-dimensional grid.
* However, if (row,col) is out-of-bounds, return OUT_BOUNDS, and if
* (row,col) is top/bottom or source/sink, return values accordingly.
* @param row
* @param col
* @return an integer that uniquely corresponds to (row,col)
*/
public int getIndex(int row, int col){
// TODO complete getIndex
return OUT_BOUNDS;
}
public void open(int i, int j) {
// TODO complete open
}
public boolean isOpen(int i, int j) {
// TODO complete isOpen
return false;
}
public boolean isFull(int i, int j) {
// TODO complete isFull
return false;
}
/**
* Returns true iff the system percolates
*/
public boolean percolates() {
// TODO complete percolates
return false;
}
// [row,col] just opened
/**
* Connect new site (row, col) to all adjacent open sites
*/
private void connect(int row, int col){
// TODO complete connect
}
}