C语言二级指针删除单链表节点

通常来说,删除单链表中的节点,需要以下步骤:

1) Find previous node of the node to be deleted.
2) Changed next of previous node.
3) Free memory for the node to be deleted.

而在coolshell上看到linus关于二级指针删除节点的表达:

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;
    }
}



你可能感兴趣的:(二级指针)