更优雅的链表操作
线索
In a 2016 TED interview (14:10) Linus Torvalds speaks about what he considers good taste in coding. As an example, he presents two implementations of item removal in singly linked lists (reproduced below). In order to remove the first item from a list, one of the implementations requires a special case, the other one does not. Linus, obviously, prefers the latter.
启发
我们能获得的启发或许是。
将节点当作二维的(因为节点中包含有线性存储的信息),那么一级指针或许是操作其中成员的优雅操作。而将节点链接为链表,整个结构变为了三维的,那么二级指针或许是操作其中成员的优雅操作。
这些都是我胡说的,并没有验证过。
但他给出的例子是顺序链表的,存在指定顺序和插入的情况。如果是无序链表,则无需考虑这些。