} while (head);
}
-
-
-DoubleLinkedList DoubleLinkedList_new(void *data){
- DoubleLinkedList head = gv_alloc(sizeof(struct DoubleLinkedList_struct));
- head->data = data;
- return head;
-}
-
-void DoubleLinkedList_delete(DoubleLinkedList head, void (*linklist_deallocator)(void*)){
- DoubleLinkedList next;
-
- if (!head) return;
- do {
- next = head->next;
- if (head->data) linklist_deallocator(head->data);
- free(head);
- head = next;
- } while (head);
-
-}
-
-
-DoubleLinkedList DoubleLinkedList_prepend(DoubleLinkedList l, void *data){
- DoubleLinkedList head = DoubleLinkedList_new(data);
- if (l){
- head->next = l;
- l->prev = head;
- }
- return head;
-}
-
-void* DoubleLinkedList_get_data(DoubleLinkedList l){
- return l->data;
-}
-
-DoubleLinkedList DoubleLinkedList_get_next(DoubleLinkedList l){
- return l->next;
-}
-
-void DoubleLinkedList_print(DoubleLinkedList head, void (*linkedlist_print)(void*)){
-
- if (!head) return;
- do {
- if (head->data) linkedlist_print(head->data);
- head = head->next;
- } while (head);
-
-}
-
-void DoubleLinkedList_delete_element(DoubleLinkedList l, void (*linklist_deallocator)(void*), DoubleLinkedList *head){
- /* delete an entry in the chain of linked list. If the head changes due to this (if l is the first element in the list), update */
- DoubleLinkedList next, prev;
-
- if (l){
- next = l->next;
- prev = l->prev;
-
- if (l->data) linklist_deallocator(l->data);
- free(l);
- l = NULL;
-
- if (next) next->prev = prev;
- if (prev) prev->next = next;
- if (!prev) *head = next;
- }
-}
void SingleLinkedList_print(SingleLinkedList head, void (*linkedlist_print)(void*));
-
-typedef struct DoubleLinkedList_struct* DoubleLinkedList;
-
-struct DoubleLinkedList_struct {
- void *data;
- DoubleLinkedList next;
- DoubleLinkedList prev;
-};
-
-DoubleLinkedList DoubleLinkedList_new(void *data);
-void DoubleLinkedList_delete(DoubleLinkedList head, void (*linklist_deallocator)(void*));
-DoubleLinkedList DoubleLinkedList_prepend(DoubleLinkedList l, void *data);
-
-void* DoubleLinkedList_get_data(DoubleLinkedList l);
-
-DoubleLinkedList DoubleLinkedList_get_next(DoubleLinkedList l);
-
-void DoubleLinkedList_delete_element(DoubleLinkedList l, void (*linklist_deallocator)(void*), DoubleLinkedList *head);
-
#ifdef __cplusplus
}
#endif