i wrote this double linked list with void pointers
typedef struct list_el
{
void *data;
struct list_el *prev;
struct list_el *next;
} list_el;
typedef struct linked_list
{
int n_el; /*number of elements*/
list_el * head; /*pointer to the head*/
list_el * tail; /*pointer to the head*/
} linked_list;
and i wrote those functions to handle with it.
/*for list_el allocation*/
list_el * new_el ( void )
{
return (list_el *) malloc(sizeof(list_el));
}
/*list initialization*/
void init_list(linked_list **l_ptr)
{
(*l_ptr) = (linked_list * )malloc(sizeof(linked_list));
(*l_ptr)->n_el = 0;
(*l_ptr)->head = NULL;
(*l_ptr)->tail = NULL;
}
/*head insertion*/
void append(void *data , linked_list **l_ptr)
{
list_el *nv;
nv = new_el();
nv->data = data;
if((*l_ptr)->n_el == 0 )
{
nv->next = nv->prev = NULL;
(*l_ptr)->head = (*l_ptr)->tail = nv;
(*l_ptr)->n_el += 1;
}
else
{
nv->next = (*l_ptr)->head;
(*l_ptr)->head->prev = nv;
(*l_ptr)->head = nv;
(*l_ptr)->n_el += 1;
}
}
I'm trying to write a find function in this way.
void * find(void * el , linked_list ** l_ptr);
where **l_ptr is the pointer to the list to search in and el is the element to search. since I'm trying to compare two void * (void * el and void *data) I do not know how to implement a comparison of this type.
Thanks.