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
+18 -18
View File
@@ -14,41 +14,41 @@ import heapq
def test_push(heap: list, val: int, flag: int = 1):
heapq.heappush(heap, flag * val) # Push the element into heap
print(f"\nElement {val} after pushed into heap")
heapq.heappush(heap, flag * val) # Element enters heap
print(f"\nAfter element {val} enters heap")
print_heap([flag * val for val in heap])
def test_pop(heap: list, flag: int = 1):
val = flag * heapq.heappop(heap) # Pop the element at the heap top
print(f"\nHeap top element {val} after exiting heap")
val = flag * heapq.heappop(heap) # Top element exits heap
print(f"\nAfter top element {val} exits heap")
print_heap([flag * val for val in heap])
"""Driver Code"""
if __name__ == "__main__":
# Initialize min-heap
# Initialize min heap
min_heap, flag = [], 1
# Initialize max-heap
# Initialize max heap
max_heap, flag = [], -1
print("\nThe following test case is for max-heap")
# Python's heapq module implements min-heap by default
# Consider "negating the elements" before entering the heap, thus reversing the comparator to implement a max-heap
# In this example, flag = 1 corresponds to min-heap, flag = -1 corresponds to max-heap
print("\nThe following test cases are for max heap")
# Python's heapq module implements min heap by default
# Consider negating the elements before entering the heap, which can reverse the size relationship, thus implementing max heap
# In this example, flag = 1 corresponds to min heap, flag = -1 corresponds to max heap
# Push the element into heap
# Elements enter heap
test_push(max_heap, 1, flag)
test_push(max_heap, 3, flag)
test_push(max_heap, 2, flag)
test_push(max_heap, 5, flag)
test_push(max_heap, 4, flag)
# Access heap top element
# Get top element
peek: int = flag * max_heap[0]
print(f"\nHeap top element is {peek}")
print(f"\nTop element is {peek}")
# Pop the element at the heap top
# Top element exits heap
test_pop(max_heap, flag)
test_pop(max_heap, flag)
test_pop(max_heap, flag)
@@ -59,13 +59,13 @@ if __name__ == "__main__":
size: int = len(max_heap)
print(f"\nNumber of heap elements is {size}")
# Determine if heap is empty
# Check if heap is empty
is_empty: bool = not max_heap
print(f"\nIs the heap empty {is_empty}")
print(f"\nIs heap empty {is_empty}")
# Enter list and build heap
# Input list and build heap
# Time complexity is O(n), not O(nlogn)
min_heap = [1, 3, 2, 5, 4]
heapq.heapify(min_heap)
print("\nEnter list and build min-heap")
print("\nAfter inputting list and building min heap")
print_heap(min_heap)