CoolShell上看到的小技巧,记下来先。
typedef std::function<bool(const node* n)> remove_fn;
void remove(node** head, remove_fn fn)
{
for (node** curr = head; *curr;) {
node* entry = *curr;
if (fn(entry)) {
*curr = entry->next;
delete entry;
} else {
curr = &entry->next;
}
}
}
网友评论