最近在看 Linux 中双向链表的实现,发现大部分代码都是能看懂的,和上学时学的内容基本一致。
什么头插法,尾插法啊乱七八糟的。
但我注意到有一点似乎不一样,在学校时,我们学的链表包括数据域和指针域,但在 Linux 中双向链表的节点是这样定义的:
1 | struct list_head { |
没有数据域
没有数据域的链表该怎么使用呢?
Recently I’ve been reading the Linux doubly-linked list implementation, and found that most of the code is understandable — basically the same as what I learned in school.
Head insertion, tail insertion, and all that stuff.
But I noticed one thing seems different: in school, we learned that a linked list node includes a data field and a pointer field, but in Linux the doubly-linked list node is defined like this:
1 | struct list_head { |
No data field
How do you use a linked list without a data field?