本文整理汇总了Java中sun.misc.Queue.enqueue方法的典型用法代码示例。如果您正苦于以下问题:Java Queue.enqueue方法的具体用法?Java Queue.enqueue怎么用?Java Queue.enqueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.misc.Queue
的用法示例。
在下文中一共展示了Queue.enqueue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printLevelOrder
import sun.misc.Queue; //导入方法依赖的package包/类
public static void printLevelOrder(Node root) throws InterruptedException {
Queue<Node> qn = new Queue<Node>();
Node temp;
if(root == null){
return;
}
qn.enqueue(root);
while(!qn.isEmpty()){
temp = qn.dequeue();
System.out.println(temp.data);
if(temp.left != null)
qn.enqueue(temp.left);
if(temp.right != null)
qn.enqueue(temp.right);
}
}
示例2: printLevelOrder
import sun.misc.Queue; //导入方法依赖的package包/类
public static void printLevelOrder(Node root) throws InterruptedException {
Node temp;
Queue<Node> qn = new Queue<Node>();
if(root == null){
return;
}
qn.enqueue(root);
while(!qn.isEmpty()) {
temp = qn.dequeue();
System.out.print(temp.data);
if(temp.left != null)
qn.enqueue(temp.left);
if(temp.right != null)
qn.enqueue(temp.right);
}
}
示例3: printLevelOrderDataInReverse
import sun.misc.Queue; //导入方法依赖的package包/类
public static void printLevelOrderDataInReverse(Node root) throws InterruptedException {
Queue<Node> qn = new Queue<Node>();
Stack<Node> sn = new Stack<Node>();
Node temp;
if(root == null) {
return;
}
qn.enqueue(root);
while(!qn.isEmpty()) {
temp = qn.dequeue();
if(temp.right != null){
qn.enqueue(temp.right);
}
if(temp.left != null){
qn.enqueue(temp.left);
}
sn.push(temp);
}
while(!sn.isEmpty()) {
System.out.print(sn.pop().data);
}
}
示例4: numberOfHalfNodes
import sun.misc.Queue; //导入方法依赖的package包/类
public static int numberOfHalfNodes(Node root) throws InterruptedException {
Queue<Node> qn = new Queue<Node>();
Node temp;
int count = 0;
if(root == null){
return 0;
}
qn.enqueue(root);
while(!qn.isEmpty()) {
temp = qn.dequeue();
if((temp.left==null && temp.right!=null) || (temp.left!=null && temp.right==null)) {
count++;
}
if(temp.left != null){
qn.enqueue(temp.left);
}
if(temp.right != null) {
qn.enqueue(temp.right);
}
}
return count;
}
示例5: bfs
import sun.misc.Queue; //导入方法依赖的package包/类
/**
* BFS for a vertex
*
* @param g - graph to be searched
* @param start - start vertex for the search operation in graph g
* @param goal - goal vertex to be searched in graph g
* @throws InterruptedException
*/
public void bfs(GraphAdjList g, Character start, Character goal) throws InterruptedException {
Queue<Character> q = new Queue<Character>();
// Set to keep track of visited nodes
Set<Character> visited = new HashSet<Character>();
// Map to hold parent-child relationship among nodes
Map<Character, Character> parentChildMap = new HashMap<Character, Character>();
Character curr;
q.enqueue(start);
visited.add(start);
while(!q.isEmpty()) {
curr = q.dequeue();
if(curr==goal) {
System.out.println("\nGoal found..."+curr);
System.out.println("visited nodes: "+visited.toString());
System.out.println("parent child map: "+parentChildMap.toString());
return;
}
System.out.print(curr+"->");
for(Character c : g.getEdgeList(curr)) {
if(!visited.contains(c)) {
visited.add(c);
parentChildMap.put(curr, c);
q.enqueue(c);
}
}
}
}