mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-06-06 05:08:45 +08:00
Fix bug in linked_list_remove_before
This commit is contained in:
@@ -338,13 +338,15 @@ void linked_list_remove(struct LinkedList<T>*& node, void(*free_func)(T) = nullp
|
|||||||
}
|
}
|
||||||
if (free_func) free_func(node->d);
|
if (free_func) free_func(node->d);
|
||||||
free(node);
|
free(node);
|
||||||
|
node = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void linked_list_remove_before(struct LinkedList<T>* node, void(*free_func)(T) = nullptr) {
|
void linked_list_remove_before(struct LinkedList<T>* node, void(*free_func)(T) = nullptr) {
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
while (node->prev) {
|
while (node->prev) {
|
||||||
linked_list_remove(node->prev, free_func);
|
struct LinkedList<T>* cur = node->prev;
|
||||||
|
linked_list_remove(cur, free_func);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user