# 通过二级指针删除链表节点看链表本质

```for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
if ((*cp)->major > major ||
((*cp)->major == major &&
(((*cp)->baseminor >= baseminor) ||
((*cp)->baseminor + (*cp)->minorct > baseminor))))
break;

...

cd->next = *cp; *cp = cd;```

```#include <stdio.h>
#include <stdlib.h>
{
int num;
};

int main()
{
int i;
for(i = 1; i < 6; i += 2)
{
tmp->num = i;
}

while(*ttmp)
{
printf("%d, %016x, %016x, %016x\n", (*ttmp)->num, ttmp, *ttmp, (*ttmp)->next);
ttmp = &((*ttmp)->next);
}

printf("============================\n");
while(*ttmp)
{
{
break;
}
ttmp = &((*ttmp)->next);
}

while(*ttmp)
{
printf("%d, %016x, %016x, %016x\n", (*ttmp)->num, ttmp, *ttmp, (*ttmp)->next);
ttmp = &((*ttmp)->next);
}

...

return 0;
}```

```void remove_if(node ** head, remove_fn rm)
{
for (node** curr = head; *curr; )
{
node * entry = *curr;
if (rm(entry))
{
*curr = entry->next;
free(entry);
}
else
curr = &entry->next;
}
}```

```// Remove all nodes from the supplied list for which the
// supplied remove function returns true.
// Returns the new head of the list.
node * remove_if(node * head, remove_fn rm)
{
for (node * prev = NULL, * curr = head; curr != NULL; )
{
node * const next = curr->next;
if (rm(curr))
{
if (prev)
prev->next = next;
else
free(curr);
}
else
prev = curr;
curr = next;
}