本文整理匯總了Java中java.util.LinkedList.offer方法的典型用法代碼示例。如果您正苦於以下問題:Java LinkedList.offer方法的具體用法?Java LinkedList.offer怎麽用?Java LinkedList.offer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.LinkedList
的用法示例。
在下文中一共展示了LinkedList.offer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: levelIterator
import java.util.LinkedList; //導入方法依賴的package包/類
/**
* 二叉樹的層序遍曆 借助於隊列來實現 借助隊列的先進先出的特性
*
* 首先將根節點入隊列 然後遍曆隊列。
* 首先將根節點打印出來,接著判斷左節點是否為空 不為空則加入隊列
* @param node
*/
public void levelIterator(BinaryNode node){
LinkedList<BinaryNode> queue = new LinkedList<>() ;
//先將根節點入隊
queue.offer(node) ;
BinaryNode current ;
while (!queue.isEmpty()){
current = queue.poll();
System.out.print(current.data+"--->");
if (current.getLeft() != null){
queue.offer(current.getLeft()) ;
}
if (current.getRight() != null){
queue.offer(current.getRight()) ;
}
}
}
示例2: mine
import java.util.LinkedList; //導入方法依賴的package包/類
/**
* Infinite loop that continuously mines blocks as soon as the
* blockchain is ready and data is available in the memPool
*/
private void mine() {
while (isRunning) {
// Get the block data from the mem pool
LinkedList<Row> blockData = new LinkedList<>();
while (blockData.size() < MAX_BLOCK_ENTRIES) {
try {
blockData.offer(mempool.take());
} catch (InterruptedException e) {
LOG.warn("Attempt to interrupt miner", e);
Thread.interrupted();
}
}
Block block = new Block();
block.setPreviousBlockHash(blocks.getLast().getHash());
block.setTimestamp(ZonedDateTime.now(UTC));
block.setData(blockData);
block.setHash(HashUtils.sha256(block.toString()));
block = proofOfWork.getProof(block);
blocks.add(block);
}
}
示例3: testOfferNull
import java.util.LinkedList; //導入方法依賴的package包/類
/**
* offer(null) succeeds
*/
public void testOfferNull() {
LinkedList q = new LinkedList();
q.offer(null);
assertNull(q.get(0));
assertTrue(q.contains(null));
}