Translate all code to English (#1836)

* Review the EN heading format.

* Fix pythontutor headings.

* Fix pythontutor headings.

* bug fixes

* Fix headings in **/summary.md

* Revisit the CN-to-EN translation for Python code using Claude-4.5

* Revisit the CN-to-EN translation for Java code using Claude-4.5

* Revisit the CN-to-EN translation for Cpp code using Claude-4.5.

* Fix the dictionary.

* Fix cpp code translation for the multipart strings.

* Translate Go code to English.

* Update workflows to test EN code.

* Add EN translation for C.

* Add EN translation for CSharp.

* Add EN translation for Swift.

* Trigger the CI check.

* Revert.

* Update en/hash_map.md

* Add the EN version of Dart code.

* Add the EN version of Kotlin code.

* Add missing code files.

* Add the EN version of JavaScript code.

* Add the EN version of TypeScript code.

* Fix the workflows.

* Add the EN version of Ruby code.

* Add the EN version of Rust code.

* Update the CI check for the English version  code.

* Update Python CI check.

* Fix cmakelists for en/C code.

* Fix Ruby comments
This commit is contained in:
Yudong Jin
2025-12-31 07:44:52 +08:00
committed by GitHub
parent 45e1295241
commit 2778a6f9c7
1284 changed files with 71557 additions and 3275 deletions

View File

@@ -9,7 +9,7 @@ package chapter_tree;
import utils.*;
import java.util.*;
/* Array-based binary tree class */
/* Binary tree class represented by array */
class ArrayBinaryTree {
private List<Integer> tree;
@@ -23,25 +23,25 @@ class ArrayBinaryTree {
return tree.size();
}
/* Get the value of the node at index i */
/* Get value of node at index i */
public Integer val(int i) {
// If the index is out of bounds, return null, representing an empty spot
// If index out of bounds, return null to represent empty position
if (i < 0 || i >= size())
return null;
return tree.get(i);
}
/* Get the index of the left child of the node at index i */
/* Get index of left child node of node at index i */
public Integer left(int i) {
return 2 * i + 1;
}
/* Get the index of the right child of the node at index i */
/* Get index of right child node of node at index i */
public Integer right(int i) {
return 2 * i + 2;
}
/* Get the index of the parent of the node at index i */
/* Get index of parent node of node at index i */
public Integer parent(int i) {
return (i - 1) / 2;
}
@@ -49,7 +49,7 @@ class ArrayBinaryTree {
/* Level-order traversal */
public List<Integer> levelOrder() {
List<Integer> res = new ArrayList<>();
// Traverse array
// Traverse array directly
for (int i = 0; i < size(); i++) {
if (val(i) != null)
res.add(val(i));
@@ -59,37 +59,37 @@ class ArrayBinaryTree {
/* Depth-first traversal */
private void dfs(Integer i, String order, List<Integer> res) {
// If it is an empty spot, return
// If empty position, return
if (val(i) == null)
return;
// Pre-order traversal
// Preorder traversal
if ("pre".equals(order))
res.add(val(i));
dfs(left(i), order, res);
// In-order traversal
// Inorder traversal
if ("in".equals(order))
res.add(val(i));
dfs(right(i), order, res);
// Post-order traversal
// Postorder traversal
if ("post".equals(order))
res.add(val(i));
}
/* Pre-order traversal */
/* Preorder traversal */
public List<Integer> preOrder() {
List<Integer> res = new ArrayList<>();
dfs(0, "pre", res);
return res;
}
/* In-order traversal */
/* Inorder traversal */
public List<Integer> inOrder() {
List<Integer> res = new ArrayList<>();
dfs(0, "in", res);
return res;
}
/* Post-order traversal */
/* Postorder traversal */
public List<Integer> postOrder() {
List<Integer> res = new ArrayList<>();
dfs(0, "post", res);
@@ -100,17 +100,17 @@ class ArrayBinaryTree {
public class array_binary_tree {
public static void main(String[] args) {
// Initialize binary tree
// Use a specific function to convert an array into a binary tree
// Here we use a function to generate a binary tree directly from an array
List<Integer> arr = Arrays.asList(1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15);
TreeNode root = TreeNode.listToTree(arr);
System.out.println("\nInitialize binary tree\n");
System.out.println("Array representation of the binary tree:");
System.out.println("Array representation of binary tree:");
System.out.println(arr);
System.out.println("Linked list representation of the binary tree:");
System.out.println("Linked list representation of binary tree:");
PrintUtil.printTree(root);
// Array-based binary tree class
// Binary tree class represented by array
ArrayBinaryTree abt = new ArrayBinaryTree(arr);
// Access node
@@ -118,19 +118,19 @@ public class array_binary_tree {
Integer l = abt.left(i);
Integer r = abt.right(i);
Integer p = abt.parent(i);
System.out.println("\nThe current node's index is " + i + ", value = " + abt.val(i));
System.out.println("Its left child's index is " + l + ", value = " + (l == null ? "null" : abt.val(l)));
System.out.println("Its right child's index is " + r + ", value = " + (r == null ? "null" : abt.val(r)));
System.out.println("Its parent's index is " + p + ", value = " + (p == null ? "null" : abt.val(p)));
System.out.println("\nCurrent node index is " + i + ", value is " + abt.val(i));
System.out.println("Its left child node index is " + l + ", value is " + (l == null ? "null" : abt.val(l)));
System.out.println("Its right child node index is " + r + ", value is " + (r == null ? "null" : abt.val(r)));
System.out.println("Its parent node index is " + p + ", value is " + (p == null ? "null" : abt.val(p)));
// Traverse tree
List<Integer> res = abt.levelOrder();
System.out.println("\nLevel-order traversal is:" + res);
res = abt.preOrder();
System.out.println("Pre-order traversal is:" + res);
System.out.println("Preorder traversal is:" + res);
res = abt.inOrder();
System.out.println("In-order traversal is:" + res);
System.out.println("Inorder traversal is:" + res);
res = abt.postOrder();
System.out.println("Post-order traversal is:" + res);
System.out.println("Postorder traversal is:" + res);
}
}