Created
October 2, 2018 20:10
-
-
Save emersion/d5c85810569e6394704797874e6eaa1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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