老外写的无法理解的链表,请解释
沧海一朵浪 2013-09-18 04:58:10 疑问1:下面的添加节点到尾部,*(head)->tqh_last = (elm);这个语句没有用,而且也没有起到添加节点的list尾部的效果
疑问2:list的位last用指针的指针有什么好处吗?
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.tqe_next = NULL; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
} while (0)
elm为一个节点
结构如下:链表的类型为下面的情况
#define TAILQ_HEAD(name, type) \
struct name { \
struct type *tqh_first; \
struct type **tqh_last; \
}
#endif
field的类型为下面的结构
struct { \
struct type *tqe_next; /* next element */ \
struct type **tqe_prev; /* address of previous next element */ \
}