本文整理匯總了Java中edu.princeton.cs.algs4.Bag類的典型用法代碼示例。如果您正苦於以下問題:Java Bag類的具體用法?Java Bag怎麽用?Java Bag使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Bag類屬於edu.princeton.cs.algs4包,在下文中一共展示了Bag類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAllValidWords
import edu.princeton.cs.algs4.Bag; //導入依賴的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;
}
示例2: main
import edu.princeton.cs.algs4.Bag; //導入依賴的package包/類
public static void main(String[] args) {
Teste t = new Teste();
Bag<String> bii = t.getB();
for (String s: bii)
StdOut.println(s);
StdOut.print("Hello WORLD!!!\n");
}
示例3: getB
import edu.princeton.cs.algs4.Bag; //導入依賴的package包/類
public Bag<String> getB() {
return b;
}