1 // DoublyLinkedList DataStructure example  BOB
   2 #ifndef DLIST_H
   3 #define DLIST_H
   4 
   5 #include <stdlib.h>
   6 
   7 typedef struct DListElmt_ {
   8     void *data;
   9     struct DListElmt_ *prev;
  10     struct DListElmt_ *next;
  11 } DListElmt;
  12 
  13 typedef struct DList_ {
  14     int size;
  15     int (*match)(const void *key1, const void *key2);
  16     void (*destroy)(void *data);
  17     DListElmt *head;
  18     DListElmt *tail;
  19 } DList;
  20 
  21 void dlist_init(DList *list, void (*dextroy)(void *data));
  22 
  23 void dlist_destroy(DList *list);
  24 
  25 int dlist_ins_next(DList *list, DListElmt *element, const void *data);
  26 
  27 int dlist_ins_prev(DList *list, DListElmt *element, const void *data);
  28 
  29 int dlist_remove(DList *list, DListElmt *element, void **data);
  30 
  31 #define dlist_size(list) ((list)->size)
  32 
  33 #define dlist_head(list) ((list)->head)
  34 
  35 #define dlist_tail(list) ((list)->tail)
  36 
  37 #define dlist_is_head(element) ((element)->prev == NULL ? 1 : 0)
  38 
  39 #define dlist_is_tail(element) ((element)->next == NULL ? 1 : 0)
  40 
  41 #define dlist_data(element) ((element)->data)
  42 
  43 #define dlist_next(element) ((element)->next)
  44 
  45 #define dlist_prev(element) ((element)->prev)
  46 
  47 #endif
  48 
web biohackers.net