i have a linked list in C which i need to destroy by request and keep memory allocation
here's the code :
can someone explain to me what exactly i need to add with the parameter dealloc?
/** Destroy and de-allocate the memory hold by a list
\param list - a pointer to an existing list
\param dealloc flag that indicates whether stored data should also be de-allocated
*/
void dbllist_destroy(dbllist_t *list,dbllist_destroy_t dealloc)
{
dbllist_node_t *current = (dbllist_node_t *)malloc(sizeof(dbllist_node_t));
dbllist_node_t *current = (dbllist_node_t *)malloc(sizeof(dbllist_node_t));
if(current == NULL || temp == NULL)
return -1;
current = dbllist_tail(list);
while (current != NULL)
{
temp = dbllist_prev(current);
free(current);
current = temp;
dbllist_size(list)--;
}
free(current);
free(temp);
free(list);
return 0;
}
typedef enum { DBLLIST_LEAVE_DATA = 0, DBLLIST_FREE_DATA } dbllist_destroy_t;