Next: , Previous: dll_udelete, Up: Doubly Linked Lists


3.2.4 dll_destroy

Destroy a node in a doubly linked list.

Synopsis

     #include <linklist/linklist.h>
     
     
     
void *dll_destroy( DLinkList ull, void *data, int (*cmp)(const void *,const void *) );

Parameters

DLinkList ull
the list to search
void *data
the data to search for
int (*cmp)(const void *,const void *)
The address of a comparison function. Set to DLL_NULL_CMP to use the list's initial comparison function.

Description

dll_destroy searches a linked list for a node which compares equivalently to the passed data. It removes the node from the list and deallocates the memory associated with it. The user must destroy the data referenced by the node's data pointer.

It uses the passed comparison routine, if available. If not, it uses that with which the list was initialized. If that is not available, a segmentation violation is unavoidable. In the former case the passed data need not have the same form as the data stored in the node.

The comparison routine is called with the passed data as the first argument and the node's data as the second argument. It must return ‘-1’, ‘0’, or ‘1’ if, respectively, the first argument is less than, equal to, or greater than the second.

Returns

It returns the node's data pointer if the node was found, NULL otherwise.