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

@@ -6,7 +6,7 @@
#include "../utils/common.hpp"
/* Array-based binary tree class */
/* Binary tree class represented by array */
class ArrayBinaryTree {
public:
/* Constructor */
@@ -19,25 +19,25 @@ class ArrayBinaryTree {
return tree.size();
}
/* Get the value of the node at index i */
/* Get value of node at index i */
int val(int i) {
// If index is out of bounds, return INT_MAX, representing a null
// Return INT_MAX if index out of bounds, representing empty position
if (i < 0 || i >= size())
return INT_MAX;
return tree[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 */
int 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 */
int 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 */
int parent(int i) {
return (i - 1) / 2;
}
@@ -45,7 +45,7 @@ class ArrayBinaryTree {
/* Level-order traversal */
vector<int> levelOrder() {
vector<int> res;
// Traverse array
// Traverse array directly
for (int i = 0; i < size(); i++) {
if (val(i) != INT_MAX)
res.push_back(val(i));
@@ -53,21 +53,21 @@ class ArrayBinaryTree {
return res;
}
/* Pre-order traversal */
/* Preorder traversal */
vector<int> preOrder() {
vector<int> res;
dfs(0, "pre", res);
return res;
}
/* In-order traversal */
/* Inorder traversal */
vector<int> inOrder() {
vector<int> res;
dfs(0, "in", res);
return res;
}
/* Post-order traversal */
/* Postorder traversal */
vector<int> postOrder() {
vector<int> res;
dfs(0, "post", res);
@@ -79,18 +79,18 @@ class ArrayBinaryTree {
/* Depth-first traversal */
void dfs(int i, string order, vector<int> &res) {
// If it is an empty spot, return
// If empty position, return
if (val(i) == INT_MAX)
return;
// Pre-order traversal
// Preorder traversal
if (order == "pre")
res.push_back(val(i));
dfs(left(i), order, res);
// In-order traversal
// Inorder traversal
if (order == "in")
res.push_back(val(i));
dfs(right(i), order, res);
// Post-order traversal
// Postorder traversal
if (order == "post")
res.push_back(val(i));
}
@@ -99,38 +99,38 @@ class ArrayBinaryTree {
/* Driver Code */
int main() {
// Initialize binary tree
// Use INT_MAX to represent an empty spot nullptr
// Use INT_MAX to represent empty position nullptr
vector<int> arr = {1, 2, 3, 4, INT_MAX, 6, 7, 8, 9, INT_MAX, INT_MAX, 12, INT_MAX, INT_MAX, 15};
TreeNode *root = vectorToTree(arr);
cout << "\nInitialize binary tree\n";
cout << "Binary tree in array representation:\n";
cout << "Array representation of binary tree:\n";
printVector(arr);
cout << "Binary tree in linked list representation:\n";
cout << "Linked list representation of binary tree:\n";
printTree(root);
// Array-based binary tree class
// Binary tree class represented by array
ArrayBinaryTree abt(arr);
// Access node
int i = 1;
int l = abt.left(i), r = abt.right(i), p = abt.parent(i);
cout << "\nCurrent node's index is " << i << ", value = " << abt.val(i) << "\n";
cout << "Its left child's index is " << l << ", value = " << (l != INT_MAX ? to_string(abt.val(l)) : "nullptr") << "\n";
cout << "Its right child's index is " << r << ", value = " << (r != INT_MAX ? to_string(abt.val(r)) : "nullptr") << "\n";
cout << "Its parent's index is " << p << ", value = " << (p != INT_MAX ? to_string(abt.val(p)) : "nullptr") << "\n";
cout << "\nCurrent node index is " << i << ", value is " << abt.val(i) << "\n";
cout << "Its left child node index is " << l << ", value is " << (abt.val(l) != INT_MAX ? to_string(abt.val(l)) : "nullptr") << "\n";
cout << "Its right child node index is " << r << ", value is " << (abt.val(r) != INT_MAX ? to_string(abt.val(r)) : "nullptr") << "\n";
cout << "Its parent node index is " << p << ", value is " << (abt.val(p) != INT_MAX ? to_string(abt.val(p)) : "nullptr") << "\n";
// Traverse tree
vector<int> res = abt.levelOrder();
cout << "\nLevel-order traversal is:";
cout << "\nLevel-order traversal: ";
printVector(res);
res = abt.preOrder();
cout << "Pre-order traversal is:";
cout << "Pre-order traversal: ";
printVector(res);
res = abt.inOrder();
cout << "In-order traversal is:";
cout << "In-order traversal: ";
printVector(res);
res = abt.postOrder();
cout << "Post-order traversal is:";
cout << "Post-order traversal: ";
printVector(res);
return 0;