typedef struct listNode {
struct listNode *prev;
struct listNode *next;
void *value;
} listNode;
typedef struct listIter {
listNode *next;
int direction;
} listIter;
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;
双向链表的结构体没有特殊的内容。节点有前驱prev,后继next,和存内容的value。迭代器有后继next和迭代方向。链表存了头head,尾tail,长度len,以及自定义的dup、free、match函数。
/* Rotate the list removing the tail node and inserting it to the head. */
void listRotate(list *list) {
listNode *tail = list->tail;
if (listLength(list) <= 1) return;
/* Detach current tail */
list->tail = tail->prev;
list->tail->next = NULL;
/* Move it as head */
list->head->prev = tail;
tail->prev = NULL;
tail->next = list->head;
list->head = tail;
}
这个函数的作用就是把链表的尾巴转到头部,实际用处还没看到,先留下一个疑问吧。
继续阅读与本文标签相同的文章
上一篇 :
上网行为管理如何实现跨网段IP-MAC绑定
下一篇 :
微信小游戏审核已支持加急申请 最快两小时通过
-
美国SpaceX公司计划向太空发射4.2万枚通信卫星
2026-05-18栏目: 教程
-
这几个小程序,让你的生活质量提高30%
2026-05-18栏目: 教程
-
超赞的二次识图精要讲解
2026-05-18栏目: 教程
-
为何如今很少看到电脑病毒?专家道出3点原因,现在知道不算晚
2026-05-18栏目: 教程
-
雷诺与Waymo将合作开发自动驾驶路线
2026-05-18栏目: 教程
