Why is pointer to a function used in linked list initialization?

algorithm, c, data-structures

Solution

The function pointer is passed to the initialization function so that the list functions will know how to destroy list entries. The list functions are designed to operate on all kinds of entries, so they need to be "told" how to destroy the particular entries this list will have.

Problem

I'm reading a book on algorithms and the author defines doubly linked list with this code: ``` void dlist_init(DList *list, void (*destroy)(void *data)); ``` What is the use of function pointer to destroy function here? Can't we just later call the destroy() function on any list? Why pass pointer to it during initialization?

Original source