Heap Assignment/malloc.c
void free(void *ptr) 
{
   num_frees++;
   if (ptr == NULL) 
   {
      return;
   }

   /* Make _block as free */
   struct _block *curr = BLOCK_HEADER(ptr);
   assert(curr->free == 0);
   curr->free = true;

   /* TODO: Coalesce free _blocks if needed */

   // For this we need to check both blocks on either side of the current block,
   // if either are free then combine the sizes of those blocks and link

      
      if(curr->next != NULL )
      {
         if (curr->next->free)
         {
            curr->size = curr->size + (curr->next->size); // add the size of the current block to the size of the next block is it is free
            curr->next = curr->next->next;
            num_coalesces++;
         }
      }
      if (curr->prev !=NULL)
      {
         if(curr->prev->free)
         {
            num_coalesces++;
            curr->prev->next = curr->next; 
            curr->prev->size = curr->size + (curr->prev->size);
         }
      }
}
/*
 * \brief free
 *
 * frees the memory _block pointed to by pointer. if the _block is adjacent
 * to another _block then coalesces (combines) them
 *
 * \param ptr the heap memory to free
 *
 * \return none
 */
\brief free
frees the memory _block pointed to by pointer. if the _block is adjacent
to another _block then coalesces (combines) them

\param ptr the heap memory to free

\return none
\ brief free frees the memory _block pointed to by pointer . if the _block is adjacent to another _block then coalesces ( combines ) them \ param ptr the heap memory to free \ return none
void free(void *ptr) 
{
   num_frees++;
   if (ptr == NULL) 
   {
      return;
   }
   struct _block *curr = BLOCK_HEADER(ptr);
   assert(curr->free == 0);
   curr->free = true;
      if(curr->next != NULL )
      {
         if (curr->next->free)
         {
            curr->size = curr->size + (curr->next->size); 
            curr->next = curr->next->next;
            num_coalesces++;
         }
      }
      if (curr->prev !=NULL)
      {
         if(curr->prev->free)
         {
            num_coalesces++;
            curr->prev->next = curr->next; 
            curr->prev->size = curr->size + (curr->prev->size);
         }
      }
}
void free ( void * ptr ) { num_frees ++ ; if ( ptr == NULL ) { return ; } struct _block * curr = BLOCK_HEADER ( ptr ) ; assert ( curr -> free == 0 ) ; curr -> free = true ; if ( curr -> next != NULL ) { if ( curr -> next -> free ) { curr -> size = curr -> size + ( curr -> next -> size ) ; curr -> next = curr -> next -> next ; num_coalesces ++ ; } } if ( curr -> prev != NULL ) { if ( curr -> prev -> free ) { num_coalesces ++ ; curr -> prev -> next = curr -> next ; curr -> prev -> size = curr -> size + ( curr -> prev -> size ) ; } } }
\brief free
 frees the memory _block pointed to by pointer.
\ brief free frees the memory _block pointed to by pointer .
/* Make _block as free */ /* TODO: Coalesce free _blocks if needed */ // For this we need to check both blocks on either side of the current block, // if either are free then combine the sizes of those blocks and link // add the size of the current block to the size of the next block is it is free