7 item
= (List
*)malloc(sizeof(List
));
8 if(item
) memset(item
, 0, sizeof(List
));
12 List
*list_last(List
*list
)
17 if(!item
) return NULL
;
18 while(item
->next
) item
= item
->next
;
22 List
*list_add(List
*list
, List
*newitem
)
26 if(!newitem
) return list
;
27 if(!list
) return newitem
;
29 lastitem
= list_last(list
);
30 lastitem
-> next
= newitem
;
31 newitem
-> prev
= lastitem
;
36 List
*list_add_data(List
*list
, void *data
)
40 newitem
= list_new_item();
41 if(!newitem
) return list
;
42 list
= list_add(list
,newitem
);
43 newitem
-> data
= data
;
47 List
*list_node_with_data(List
*list
, void *data
)
53 if(item
->data
== data
) return item
;
59 int list_length(List
*list
)
73 List
*list_nth_node(List
*list
, int index
)
81 if( i
== index
) return item
;
88 List
*list_remove_node(List
*list
, List
*node
)
92 if(!list
) return list
;
93 if(!node
) return list
;
99 if(prev
) prev
->next
= next
;
100 if(next
) next
->prev
= prev
;
101 if(prev
) return list
;
105 List
*list_delete_node(List
*list
, List
*node
)
107 list
= list_remove_node(list
,node
);
112 void list_for_each(List
*list
, list_for_each_function func
, void *data
)
120 if( func(item
, data
) ) return;
125 void list_free(List
*list
)
129 item
= list_last(list
);
138 int list_has_node(List
*list
, List
*node
)
142 for(i
=list
; i
; i
= i
->next
) {
143 if( i
== node
) return 1;