diff --git a/include/list.h b/include/list.h index 527cf85..a1e1917 100644 --- a/include/list.h +++ b/include/list.h @@ -18,6 +18,9 @@ liftoff_list_insert(struct liftoff_list *list, struct liftoff_list *elm); void liftoff_list_remove(struct liftoff_list *elm); +void +liftoff_list_swap(struct liftoff_list *this, struct liftoff_list *other); + size_t liftoff_list_length(const struct liftoff_list *list); diff --git a/list.c b/list.c index e8d37b0..13c5cfd 100644 --- a/list.c +++ b/list.c @@ -25,6 +25,19 @@ liftoff_list_remove(struct liftoff_list *elm) elm->prev = NULL; } +void +liftoff_list_swap(struct liftoff_list *this, struct liftoff_list *other) +{ + struct liftoff_list tmp; + + liftoff_list_insert(other, &tmp); + liftoff_list_remove(other); + liftoff_list_insert(this, other); + liftoff_list_remove(this); + liftoff_list_insert(&tmp, this); + liftoff_list_remove(&tmp); +} + size_t liftoff_list_length(const struct liftoff_list *list) {