本文整理汇总了Java中edu.princeton.cs.algs4.WeightedQuickUnionUF类的典型用法代码示例。如果您正苦于以下问题:Java WeightedQuickUnionUF类的具体用法?Java WeightedQuickUnionUF怎么用?Java WeightedQuickUnionUF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WeightedQuickUnionUF类属于edu.princeton.cs.algs4包,在下文中一共展示了WeightedQuickUnionUF类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: Percolation
import edu.princeton.cs.algs4.WeightedQuickUnionUF; //导入依赖的package包/类
public Percolation(int n){// create n-by-n grid, with all sites blocked
if (n <= 0) throw new java.lang.IllegalArgumentException("IllegalArgument");
N = n;
count = 0;
uf = new WeightedQuickUnionUF(N*N + 2);
id = new int[N+1][N+1];
status = new int[N+1][N+1];
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
id[i][j] = (i-1) * N + j-1;
status[i][j] = 0;
}
}
virtual_top = N*N;
virtual_bottom = N*N + 1;
}
开发者ID:Lxinyuelxy,项目名称:Princeton_Algorithms,代码行数:17,代码来源:Percolation.java
示例2: Percolation
import edu.princeton.cs.algs4.WeightedQuickUnionUF; //导入依赖的package包/类
/**
* create n-by-n grid, with all sites blocked
* @param n
* grid的大小
*/
public Percolation(int n) {
if (n < 1)
throw new IllegalArgumentException("Argument " + n + " is invalid.");
this.n = n;
//额外添加两个Virtual Site(分别为最顶端和最底部)
wquTopModel = new WeightedQuickUnionUF(n * n + 1);
wquBottomModel = new WeightedQuickUnionUF(n * n + 1);
sites = new boolean[n * n];
}
开发者ID:DCMMC,项目名称:Java-Algorithms-Learning,代码行数:18,代码来源:Percolation.java
示例3: Percolation
import edu.princeton.cs.algs4.WeightedQuickUnionUF; //导入依赖的package包/类
public Percolation(int n) {
if (n <= 0) throw new IllegalArgumentException();
uf = new WeightedQuickUnionUF((n * n) + 2);
isOpenSite = new boolean[(n * n) + 2];
length = n;
topnode = n * n;
bottomnode = (n * n) + 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) isOpenSite[index(i + 1, j + 1)] = false;
}
}
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:14,代码来源:Percolation.java
示例4: Percolation
import edu.princeton.cs.algs4.WeightedQuickUnionUF; //导入依赖的package包/类
public Percolation(int n) {
if (n <= 0)
throw new java.lang.IllegalArgumentException("n must be > 0 !");
this.n = n;
virt1 = n*n;
virt2 = n*n + 1;
grid = new int[n][n];
// Creates the grid plus 2 virtual sites: n² + 1 and n² + 2
uf = new WeightedQuickUnionUF(n*n + 2);
ufAux = new WeightedQuickUnionUF(n*n + 1);
}
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:13,代码来源:Percolation.java
示例5: Percolation
import edu.princeton.cs.algs4.WeightedQuickUnionUF; //导入依赖的package包/类
public Percolation(int N)
{
if (N < 1)
{
throw new IllegalArgumentException("N must be at least 1!");
}
this.N = N;
int size = N * N;
sites = new Site[N][N];
uf1 = new WeightedQuickUnionUF(size + 2);
uf2 = new WeightedQuickUnionUF(size + 1);
top = size;
bottom = size + 1;
for (int i = 0; i < N; ++i)
{
for (int j = 0; j < N; ++j)
{
sites[i][j] = new Site(i, j);
}
}
}
开发者ID:goldsborough,项目名称:algs4,代码行数:30,代码来源:Percolation.java
注:本文中的edu.princeton.cs.algs4.WeightedQuickUnionUF类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论