File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,13 @@ typedef struct max_heap
1111
1212Heap * create_heap (Heap * heap ); /*Creates a max_heap structure and returns a
1313 pointer to the struct*/
14+ /**
15+ * @brief Deallocates memory associated with a given heap.
16+ *
17+ * @param heap Pointer to the heap structure to be deallocated.
18+ */
19+ void delete_heap (Heap * const heap );
20+
1421void down_heapify (Heap * heap , int index ); /*Pushes an element downwards in the
1522 heap to find its correct position*/
1623void up_heapify (Heap * heap , int index ); /*Pushes an element upwards in the heap
@@ -46,6 +53,7 @@ int main()
4653 printf ("Popping an element.\n" );
4754 printf ("Top element = %d \n" , top (head ));
4855 printf ("\n" );
56+ delete_heap (head );
4957 return 0 ;
5058}
5159Heap * create_heap (Heap * heap )
@@ -57,6 +65,16 @@ Heap *create_heap(Heap *heap)
5765 return heap ;
5866}
5967
68+ void delete_heap (Heap * const heap )
69+ {
70+ if (heap == NULL )
71+ {
72+ return ;
73+ }
74+ free (heap -> p );
75+ free (heap );
76+ }
77+
6078void down_heapify (Heap * heap , int index )
6179{
6280 if (index >= heap -> count )
You can’t perform that action at this time.
0 commit comments