Files
hello-algo/ru/codes/c/chapter_heap/my_heap_test.c
Yudong Jin 772183705e Add ru version (#1865)
* Add Russian docs site baseline

* Add Russian localized codebase

* Polish Russian code wording

* Update ru code translation.

* Update code translation and chapter covers.

* Fix pythontutor extraction.

* Add README and landing page.

* placeholder of profiles

* Use figures of English version

* Remove chapter paperbook
2026-03-28 04:24:07 +08:00

42 lines
1.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* File: my_heap_test.c
* Created Time: 2023-01-15
* Author: Reanon (793584285@qq.com)
*/
#include "my_heap.c"
/* Driver Code */
int main() {
/* Инициализация кучи */
// Инициализация максимальной кучи
int nums[] = {9, 8, 6, 6, 7, 5, 2, 1, 4, 3, 6, 2};
MaxHeap *maxHeap = newMaxHeap(nums, sizeof(nums) / sizeof(int));
printf("После построения кучи из входного массива\n");
printHeap(maxHeap->data, maxHeap->size);
/* Получение элемента с вершины кучи */
printf("\nВерхний элемент кучи = %d\n", peek(maxHeap));
/* Добавление элемента в кучу */
push(maxHeap, 7);
printf("\nПосле добавления элемента 7 в кучу\n");
printHeap(maxHeap->data, maxHeap->size);
/* Извлечение элемента с вершины кучи */
int top = pop(maxHeap);
printf("\nПосле извлечения верхнего элемента %d из кучи\n", top);
printHeap(maxHeap->data, maxHeap->size);
/* Получение размера кучи */
printf("\nКоличество элементов в куче = %d\n", size(maxHeap));
/* Проверка, пуста ли куча */
printf("\nПуста ли куча: %d\n", isEmpty(maxHeap));
// Освободить память
delMaxHeap(maxHeap);
return 0;
}