Last active
August 14, 2016 02:19
-
-
Save alanduan/90ba2d4bffd0b3daccafd1b1ebb2a9db to your computer and use it in GitHub Desktop.
[structure] dlist
This file contains hidden or 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
| typedef struct dlist_s dlist_t; | |
| struct dlist_s | |
| { | |
| dlist_t *next; | |
| dlist_t *prev; | |
| }; | |
| void dlist_init(dlist_t *list) | |
| { | |
| list->prev = list->next = list; | |
| } | |
| void dlist_append(dlist_t *list, dlist_t *item) | |
| { | |
| item->next = list; | |
| item->prev = list->prev; | |
| item->next->prev = item->prev->next = item; | |
| } | |
| void dlist_prepend(dlist_t *list, dlist_t *item) | |
| { | |
| item->next = list->next; | |
| item->prev = list; | |
| item->next->prev = item->prev->next = item; | |
| } | |
| void dlist_unlink(dlist *item) | |
| { | |
| item->prev->next = item->next; | |
| item->next->prev = item->prev; | |
| } | |
| bool dlist_is_empty(dlist_t *list) | |
| { | |
| return list->next = list; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment