linked_list: Implement linked_list_take

This commit is contained in:
Kenny Levinsen 2020-08-30 00:05:19 +02:00
parent 5470c48113
commit c36cc962e6
4 changed files with 61 additions and 8 deletions

View file

@ -32,3 +32,17 @@ bool linked_list_empty(struct linked_list *list) {
assert(list->prev != NULL && list->next != NULL);
return list->next == list;
}
void linked_list_take(struct linked_list *target, struct linked_list *source) {
if (linked_list_empty(source)) {
linked_list_init(target);
return;
}
target->next = source->next;
target->prev = source->prev;
target->next->prev = target;
target->prev->next = target;
linked_list_init(source);
}