- 论坛徽章:
- 95
|
看有些链表中定义的item,并非使用 *next, *prev,
而是向前指针使用二重指针
类似如下这种:
struct ...
aomw10 发表于 2011-06-21 20:24 ![]()
这是 Minix 3 内核代码 kernel/proc.c 中给出的解释:
- * The code here is critical to make everything work and is important for the
- * overall performance of the system. A large fraction of the code deals with
- * list manipulation. To make this both easy to understand and fast to execute
- * pointer pointers are used throughout the code. Pointer pointers prevent
- * exceptions for the head or tail of a linked list.
- *
- * node_t *queue, *new_node; // assume these as global variables
- * node_t **xpp = &queue; // get pointer pointer to head of queue
- * while (*xpp != NULL) // find last pointer of the linked list
- * xpp = &(*xpp)->next; // get pointer to next pointer
- * *xpp = new_node; // now replace the end (the NULL pointer)
- * new_node->next = NULL; // and mark the new end of the list
- *
- * For example, when adding a new node to the end of the list, one normally
- * makes an exception for an empty list and looks up the end of the list for
- * nonempty lists. As shown above, this is not required with pointer pointers.
- */
复制代码 |
|