publicclassPercolation { publicPercolation(int N)// create N-by-N grid, with all sites initially blocked publicvoidopen(int row, int col)// open the site (row, col) if it is not open already publicbooleanisOpen(int row, int col)// is the site (row, col) open? publicbooleanisFull(int row, int col)// is the site (row, col) full? publicintnumberOfOpenSites()// number of open sites publicbooleanpercolates()// does the system percolate? }
The
WeightedQuickUnionUF class
作业提供了一个带权并查集的类,实现以上API时必须要用到该并查集,接口如下:
1 2 3 4 5 6 7
publicclassWeightedQuickUnionUF { publicWeightedQuickUnionUF(int n)// creates a UF with n elements publicintcount()// number of disjoint sets publicintfind(int p)// the root of p's set publicbooleanconnected(int p, int q)// whether p and q are in the same set publicvoidunion(int p, int q)// join p and q's sets together }