package structure.tree.traverse;
import java.util.LinkedList;
import structure.tree.node.Node_01;
public class LevelTraverser {
public void levelTraverse(Node_01 n){
LinkedList<Node_01> queue=new LinkedList<Node_01>();
queue.offer(n);
while(!queue.isEmpty()){
n=queue.poll();
if(n!=null){
System.out.print(n.data+" ");
queue.offer(n.left);
queue.offer(n.right);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
树的层次遍历
最新推荐文章于 2022-12-29 18:05:56 发布