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