Last active
December 12, 2015 03:38
-
-
Save ahappyforest/4707963 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 这个是linus称为懂指针的人写的链表删除操作. | |
分析在1. (http://coolshell.cn/articles/8990.html) | |
2. (http://wordaligned.org/articles/two-star-programming) | |
*/ | |
#include <stdio.h> | |
typedef struct node { | |
struct node *next; | |
} node; | |
typedef bool (*remove_fn)(node const *v); | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment