频道栏目
首页 > 资讯 > Java > 正文

Java数据结构系列之——树(6):二叉树的层序遍历

14-12-06        来源:[db:作者]  
收藏   我要投稿
package tree.binarytree;

import java.util.LinkedList;

/**
 * 层序遍历二叉树
 * 
 * @author wl
 * 
 */
public class PrintFromTopToBotton {
	public static void printfromtoptobotton(BiTreeNode root) {
		if (root == null) {
			return;
		}

		LinkedList queue = new LinkedList();
		queue.addLast(root);
		
		while (queue.size() != 0) {
			BiTreeNode current = queue.pollFirst();
			System.out.println(current.data);

			if (current.leftNode != null) {
				queue.addLast(current.leftNode);
			}

			if (current.rightNode != null) {
				queue.addLast(current.rightNode);
			}
		}
	}
}

相关TAG标签
上一篇:BZOJ 2760 JLOI 2011 小A的烦恼 模拟
下一篇:HDU 3635 Dragon Balls (并查集)
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站