Retranslate the complete English edition from Simplified Chinese (#2010)

* Retranslate the complete English edition from Simplified Chinese

* Polish three English explanations after reader-focused review
This commit is contained in:
Yudong Jin
2026-10-31 03:35:51 +08:00
committed by GitHub
parent ef46e2ed95
commit 14c314c08c
1502 changed files with 29459 additions and 23517 deletions

View File

@@ -12,31 +12,31 @@ import java.util.*;
public class binary_tree_bfs {
/* Level-order traversal */
static List<Integer> levelOrder(TreeNode root) {
// Initialize queue, add root node
// Initialize a queue and enqueue the root
Queue<TreeNode> queue = new LinkedList<>();
queue.add(root);
// Initialize a list to save the traversal sequence
// Initialize a list to store the traversal sequence
List<Integer> list = new ArrayList<>();
while (!queue.isEmpty()) {
TreeNode node = queue.poll(); // Dequeue
list.add(node.val); // Save node value
TreeNode node = queue.poll(); // Dequeue from the queue
list.add(node.val); // Store the node value
if (node.left != null)
queue.offer(node.left); // Left child node enqueue
queue.offer(node.left); // Enqueue the left child
if (node.right != null)
queue.offer(node.right); // Right child node enqueue
queue.offer(node.right); // Enqueue the right child
}
return list;
}
public static void main(String[] args) {
/* Initialize binary tree */
// Here we use a function to generate a binary tree directly from an array
/* Initialize the binary tree */
// Use a helper function that builds a binary tree directly from an array
TreeNode root = TreeNode.listToTree(Arrays.asList(1, 2, 3, 4, 5, 6, 7));
System.out.println("\nInitialize binary tree\n");
System.out.println("\nInitialize the binary tree\n");
PrintUtil.printTree(root);
/* Level-order traversal */
List<Integer> list = levelOrder(root);
System.out.println("\nLevel-order traversal node print sequence = " + list);
System.out.println("\nNode sequence from level-order traversal = " + list);
}
}