shlyのspace

每天进步一点点


  • 首页

  • 分类

  • 归档

  • 标签

广度优先遍历

发表于 2016-06-19   |   分类于 学习笔记 , 数据结构   |  

二叉树的广度优先遍历

public void breadFirst(TreeNode root){
        Queue<TreeNode> queue = new ArrayDeque<TreeNode>();
        if(root!=null){
            queue.add(root);
            while(!queue.isEmpty()){
                TreeNode p = queue.poll();
                System.out.print(p.val);
                if(p.left!=null){
                    queue.offer(p.left);
                }
                if(p.right!=null){
                    queue.offer(p.right);
                }
            }
        }
    }
#数据结构 #二叉树 #广度优先遍历
java中的Queue与Deque
Variance
  • 文章目录
  • 站点概览
shly

shly

To get one thing, the best way is to prove that you deserve it

52 日志
11 分类
50 标签
GitHub Weibo

此文章未包含目录

© 2017 shly
由 Hexo 强力驱动
主题 - NexT.Pisces