一、实现
定义在adlist.h文件。链表被实现为双向链表
二、数据结构
1. listNode结构 : ![11fd3471330fa618dbdd2cbaaba9f09e663.jpg](https://oscimg.oschina.net/oscnet/11fd3471330fa618dbdd2cbaaba9f09e663.jpg)
typedef struct listNode {
struct listNode *prev;
struct listNode *next;
void *value;
} listNode;
2. list结构 : ![c329ebeb02ab1978465b3689bf108cc483b.jpg](https://oscimg.oschina.net/oscnet/c329ebeb02ab1978465b3689bf108cc483b.jpg)
typedef struct list {
listNode *head;
listNode *tail;
void *(*dup)(void *ptr);
void (*free)(void *ptr);
int (*match)(void *ptr, void *key);
unsigned long len;
} list;
3. listIter结构 : ![4f17f63d17dbe071cdcf689b0083865ad64.jpg](https://oscimg.oschina.net/oscnet/4f17f63d17dbe071cdcf689b0083865ad64.jpg)
typedef struct listIter {
listNode *next;
int direction;
} listIter;
/* Directions for iterators */
#define AL_START_HEAD 0
#define AL_START_TAIL 1
0表示从表头开始 -> 表尾迭代,1表示从表尾开始 -> 表头迭代。