Report a Heap's Count, and Whether It Is Empty or Full
Report a Heap's Count, and Whether It Is Empty or Full
Complete the three small functions every other heap function leans on: min_heap_empty, min_heap_full and min_heap_count. Each one answers a question about the heap without changing it.
Reminder: how this min heap is stored. A min_heap is a struct with three fields: capacity (the most values it can hold), count (how many it holds now) and values (a pointer to an array made with malloc). The heap is a complete binary tree kept in that array, filled row by row with no gaps, so only slots 0 to count - 1 are in use. Every parent is smaller than or equal to its children, so the smallest value is always at index 0. For the value at index i, the parent is at (i - 1) / 2 and the children are at 2 * i + 1 and 2 * i + 2.
a heap made with room for 5 values, holding 3:
2
/ \
6 4
capacity: 5
count: 3
values: 2 6 4 ? ? (slots 3 and 4 are spare room)
index: 0 1 2 3 4
empty? no (count is not 0)
full? no (count has not reached capacity)Nothing here needs a loop. The two counters in the struct already hold every answer, so each function is one line.
Requirements:
1. min_heap_empty returns true when the heap holds no values, false otherwise.
2. min_heap_full returns true when count has reached capacity, false otherwise.
3. min_heap_count returns how many values the heap holds.
4. Do not change the heap, and leave min_heap_initialize and min_heap_destroy as they are.
Do NOT write a main function.
Expected Output:
count 0, empty yes, full no count 1, empty no, full no count 3, empty no, full yes
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...