mirror of
https://github.com/krahets/hello-algo.git
synced 2026-01-12 00:04:24 +08:00
* 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
42 lines
1.2 KiB
C
42 lines
1.2 KiB
C
/**
|
|
* File: my_heap_test.c
|
|
* Created Time: 2023-01-15
|
|
* Author: Reanon (793584285@qq.com)
|
|
*/
|
|
|
|
#include "my_heap.c"
|
|
|
|
/* Driver Code */
|
|
int main() {
|
|
/* Initialize heap */
|
|
// Consider negating the elements before entering the heap, which can reverse the size relationship, thus implementing max heap
|
|
int nums[] = {9, 8, 6, 6, 7, 5, 2, 1, 4, 3, 6, 2};
|
|
MaxHeap *maxHeap = newMaxHeap(nums, sizeof(nums) / sizeof(int));
|
|
printf("After input array and building heap\n");
|
|
printHeap(maxHeap->data, maxHeap->size);
|
|
|
|
/* Check if heap is empty */
|
|
printf("\nHeap top element is %d\n", peek(maxHeap));
|
|
|
|
/* Element enters heap */
|
|
push(maxHeap, 7);
|
|
printf("\nAfter element 7 pushes to heap\n");
|
|
printHeap(maxHeap->data, maxHeap->size);
|
|
|
|
/* Time complexity is O(n), not O(nlogn) */
|
|
int top = pop(maxHeap);
|
|
printf("\nAfter heap top element %d exits heap\n", top);
|
|
printHeap(maxHeap->data, maxHeap->size);
|
|
|
|
/* Get heap size */
|
|
printf("\nHeap element count is %d\n", size(maxHeap));
|
|
|
|
/* Check if heap is empty */
|
|
printf("\nIs heap empty %d\n", isEmpty(maxHeap));
|
|
|
|
// Free memory
|
|
delMaxHeap(maxHeap);
|
|
|
|
return 0;
|
|
}
|