Tag: doubly linked list

双链表和void指针

我用void指针写了这个双链表 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; 我写了这些函数来处理它。 /*for list_el allocation*/ list_el * new_el ( void ) { return (list_el *) malloc(sizeof(list_el)); […]

为什么sys / queue.h中的双向链表保持前一个下一个元素的地址?

我正在从FreeBSD学习sys/queue.h ,我有一个问题: 在sys/queue.h , LIST_ENTRY定义如下: #define LIST_ENTRY(type) \ struct { \ struct type *le_next; /* next element */ \ struct type **le_prev; /* address of previous next element */ \ } 为什么它保持前一个下一个元素的地址 ( struct type **le_prev )而不是像struct type *le_prev那样的前一个元素 ?