我正在阅读Merging two sorted linked list的答案。编码:
#define SWAP_PTRS(a, b) do { void *t = (a); (a) = (b); (b) = t; } while (0)
Node* MergeLists(Node* list1, Node* list2)
{
Node *list = NULL, **pnext = &list;
if (list2 == NULL)
return list1;
while (list1 != NULL)
{
if (list1->data > list2->data)
SWAP_PTRS(list1, list2);
// What does the following piece of code do ?
*pnext = list1; // ??
pnext = &list1->next; // ??
list1 = *pnext; // ??
}
*pnext = list2;
return list;
}
我无法理解双指针在这里是如何工作的,值是如何改变的?