Skip to content

Instantly share code, notes, and snippets.

@emersion
Created October 2, 2018 20:10
Show Gist options
  • Save emersion/d5c85810569e6394704797874e6eaa1b to your computer and use it in GitHub Desktop.
Save emersion/d5c85810569e6394704797874e6eaa1b to your computer and use it in GitHub Desktop.
struct list {
void *value;
struct list *prev, *next;
};
void list_init(struct list *l) {
assert(l->prev == NULL && l->next == NULL);
l->prev = l;
l->next = l;
}
void list_insert(struct list *l, struct list *elem, void *value) {
assert(elem->prev == NULL && elem->next == NULL);
elem->value = value;
elem->prev = l;
elem->next = l->next;
l->next = elem;
elem->next->prev = elem;
}
void list_remove(struct list *elem) {
assert(elem->prev != NULL && elem->next != NULL);
elem->prev->next = elem->next;
elem->next->prev = elem->prev;
l->prev = l->next = NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment