二叉树广度优先遍历和深度优先遍历
https://blog.csdn.net/XTAOTWO/article/details/83625586
广度优先遍历
public List<Integer> bfs(TreeNode root) { Queue<TreeNode> queue = new LinkedList<TreeNode>(); List<Integer> list = new LinkedList<Integer>(); if (root == null) { return list; } queue.add(root); while (!queue.isEmpty()) { TreeNode treeNode = queue.remove(); if (null != treeNode.leftNode) { queue.add(treeNode.leftNode); } if (null != treeNode.rightNode) { queue.add(treeNode.rightNode); } list.add(treeNode.val); } return list; }