mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-08 05:26:07 +00:00
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:
@@ -7,40 +7,40 @@
|
||||
#include "../utils/common.hpp"
|
||||
|
||||
void testPush(priority_queue<int> &heap, int val) {
|
||||
heap.push(val); // Push the element into heap
|
||||
cout << "\nAfter element " << val << " is added to the heap" << endl;
|
||||
heap.push(val); // Element enters heap
|
||||
cout << "\nAfter element " << val << " pushes to heap" << endl;
|
||||
printHeap(heap);
|
||||
}
|
||||
|
||||
void testPop(priority_queue<int> &heap) {
|
||||
int val = heap.top();
|
||||
heap.pop();
|
||||
cout << "\nAfter the top element " << val << " is removed from the heap" << endl;
|
||||
cout << "\nAfter heap top element " << val << " pops from heap" << endl;
|
||||
printHeap(heap);
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
int main() {
|
||||
/* Initialize the heap */
|
||||
// Initialize min-heap
|
||||
/* Initialize heap */
|
||||
// Python's heapq module implements min heap by default
|
||||
// priority_queue<int, vector<int>, greater<int>> minHeap;
|
||||
// Initialize max-heap
|
||||
// Consider negating the elements before entering the heap, which can reverse the size relationship, thus implementing max heap
|
||||
priority_queue<int, vector<int>, less<int>> maxHeap;
|
||||
|
||||
cout << "\nThe following test case is for max-heap" << endl;
|
||||
cout << "\nThe following test cases are for max heap" << endl;
|
||||
|
||||
/* Push the element into heap */
|
||||
/* Element enters heap */
|
||||
testPush(maxHeap, 1);
|
||||
testPush(maxHeap, 3);
|
||||
testPush(maxHeap, 2);
|
||||
testPush(maxHeap, 5);
|
||||
testPush(maxHeap, 4);
|
||||
|
||||
/* Access heap top element */
|
||||
/* Check if heap is empty */
|
||||
int peek = maxHeap.top();
|
||||
cout << "\nTop element of the heap is " << peek << endl;
|
||||
cout << "\nHeap top element is " << peek << endl;
|
||||
|
||||
/* Pop the element at the heap top */
|
||||
/* Time complexity is O(n), not O(nlogn) */
|
||||
testPop(maxHeap);
|
||||
testPop(maxHeap);
|
||||
testPop(maxHeap);
|
||||
@@ -49,17 +49,17 @@ int main() {
|
||||
|
||||
/* Get heap size */
|
||||
int size = maxHeap.size();
|
||||
cout << "\nNumber of elements in the heap is " << size << endl;
|
||||
cout << "\nHeap size is " << size << endl;
|
||||
|
||||
/* Determine if heap is empty */
|
||||
/* Check if heap is empty */
|
||||
bool isEmpty = maxHeap.empty();
|
||||
cout << "\nIs the heap empty " << isEmpty << endl;
|
||||
cout << "\nIs heap empty " << isEmpty << endl;
|
||||
|
||||
/* Enter list and build heap */
|
||||
/* Input list and build heap */
|
||||
// Time complexity is O(n), not O(nlogn)
|
||||
vector<int> input{1, 3, 2, 5, 4};
|
||||
priority_queue<int, vector<int>, greater<int>> minHeap(input.begin(), input.end());
|
||||
cout << "After inputting the list and building a min-heap" << endl;
|
||||
cout << "After input list and building min heap" << endl;
|
||||
printHeap(minHeap);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user