mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-04 03:14:09 +08:00
refactor: Replace 结点 with 节点 (#452)
* Replace 结点 with 节点 Update the footnotes in the figures * Update mindmap * Reduce the size of the mindmap.png
This commit is contained in:
@@ -12,17 +12,17 @@ import java.util.*;
|
||||
public class binary_tree_bfs {
|
||||
/* 层序遍历 */
|
||||
static List<Integer> levelOrder(TreeNode root) {
|
||||
// 初始化队列,加入根结点
|
||||
// 初始化队列,加入根节点
|
||||
Queue<TreeNode> queue = new LinkedList<>() {{ add(root); }};
|
||||
// 初始化一个列表,用于保存遍历序列
|
||||
List<Integer> list = new ArrayList<>();
|
||||
while (!queue.isEmpty()) {
|
||||
TreeNode node = queue.poll(); // 队列出队
|
||||
list.add(node.val); // 保存结点值
|
||||
list.add(node.val); // 保存节点值
|
||||
if (node.left != null)
|
||||
queue.offer(node.left); // 左子结点入队
|
||||
queue.offer(node.left); // 左子节点入队
|
||||
if (node.right != null)
|
||||
queue.offer(node.right); // 右子结点入队
|
||||
queue.offer(node.right); // 右子节点入队
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -36,6 +36,6 @@ public class binary_tree_bfs {
|
||||
|
||||
/* 层序遍历 */
|
||||
List<Integer> list = levelOrder(root);
|
||||
System.out.println("\n层序遍历的结点打印序列 = " + list);
|
||||
System.out.println("\n层序遍历的节点打印序列 = " + list);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user