本文整理汇总了Java中edu.princeton.cs.algs4.SET类的典型用法代码示例。如果您正苦于以下问题:Java SET类的具体用法?Java SET怎么用?Java SET使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SET类属于edu.princeton.cs.algs4包,在下文中一共展示了SET类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: simple
import edu.princeton.cs.algs4.SET; //导入依赖的package包/类
/**
* Returns a random simple graph containing <tt>V</tt> vertices and <tt>E</tt> edges.
* @param V the number of vertices
* @param E the number of vertices
* @return a random simple graph on <tt>V</tt> vertices, containing a total
* of <tt>E</tt> edges
* @throws IllegalArgumentException if no such simple graph exists
*/
public static Graph simple(int V, int E) {
if (E > (long) V*(V-1)/2) throw new IllegalArgumentException("Too many edges");
if (E < 0) throw new IllegalArgumentException("Too few edges");
Graph G = new Graph(V);
SET<Edge> set = new SET<Edge>();
while (G.E() < E) {
int v = StdRandom.uniform(V);
int w = StdRandom.uniform(V);
Edge e = new Edge(v, w);
if ((v != w) && !set.contains(e)) {
set.add(e);
G.addEdge(v, w);
}
}
return G;
}
示例2: getAllValidWords
import edu.princeton.cs.algs4.SET; //导入依赖的package包/类
public Iterable<String> getAllValidWords(BoggleBoard board) {
this.board = board;
rows = board.rows();
cols = board.cols();
adj = (Bag<Integer>[]) new Bag[rows*cols];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
int v = i*cols + j;
adj[v] = new Bag<Integer>();
if (checkWIsValid(i-1, j)) adj[v].add((i-1) * cols + j);
if (checkWIsValid(i+1, j)) adj[v].add((i+1) * cols + j);
if (checkWIsValid(i, j+1)) adj[v].add(i * cols + j+1);
if (checkWIsValid(i, j-1)) adj[v].add(i * cols + j-1);
if (checkWIsValid(i+1, j-1)) adj[v].add((i+1) * cols + j-1);
if (checkWIsValid(i+1, j+1)) adj[v].add((i+1) * cols + j+1);
if (checkWIsValid(i-1, j-1)) adj[v].add((i-1) * cols + j-1);
if (checkWIsValid(i-1, j+1)) adj[v].add((i-1) * cols + j+1);
}
}
validWords = new SET<String>();
for (int v = 0; v < rows*cols; v++) {
visitingDices = new Stack<Integer>();
marked = new boolean[rows*cols];
visitingDices.push(v);
marked[v] = true;
if(getLetterOnBoard(v) == 'Q')
searchValidWords(v, root.next['Q'-'A'].next['U' - 'A'], "QU", visitingDices);
else
searchValidWords(v, root.next[getLetterOnBoard(v)-'A'], getLetterOnBoard(v) + "", visitingDices);
}
return validWords;
}