//层序遍历二叉树
public class Node{
public int value;
public Node left;
public Node right;
public Node(int data){
this.value=data;
}
}
//利用队列
public void layerTranverse(){
if(root==null){
return;
}
Queue<Node> queue=new LinkedList<Node>();
queue.add(root);
while(!queue.isEmpty()){
Node node=queue.poll();
System.out.println(node.value);
System.out.println(" ");
if(node.left!=null){
queue.add(node.left);
}
if(node.right!=null){
queue.add(node.right);
}
}
}