Java 二叉树广度优先遍历
2016-02-23 19:03
405 查看
广度优先遍历需要用的辅助数据结构为:队列
private void levelOrderTraversalNoRecursive() { if (root==null) { System.out.println("empty tree"); } ArrayDeque<TreeNode> queue = new ArrayDeque<TreeNode>(); queue.add(root); while(!queue.isEmpty()) { TreeNode ctn = queue.remove(); System.out.print(ctn.value+" "); if (ctn.left!=null) { queue.add(ctn.left); } if (ctn.right!=null) { queue.add(ctn.right); } } }
相关文章推荐
- Java 数组构建二叉树
- RxJava操作符
- 执行插入操作后,如何返回自动增长的ID(Java)
- Spring的事务处理机制及JAVA异常
- Java 调用Dll
- Spring的AOP配置
- java中== equals 和comparTo的区别
- 关于context:component-scan扫描spring注解标记的用法
- 查看java进程的所有信息
- JAVA简易WEB服务器(二)
- Vin验证工具类
- maven工程出现java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- JAVA运行时异常及常见的5中RuntimeExecption
- javaEE 后台框架 SpringMVC Mybatis Shiro druid
- Java中内存分配
- HDU1000A + B Problem(入门题,c,Java)
- java与C#的简单比较
- Spring加载配置文件
- Java回调机制与OOP思想
- org.springframework.web.context.ContextLoaderListener找不到的解决方法