-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.c
36 lines (30 loc) · 575 Bytes
/
list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Double linked list
#include "list.h"
void list_init (list_s * root)
{
root->prev = root;
root->next = root;
}
#define LIST_LINK \
prev->next = node; \
node->prev = prev; \
next->prev = node; \
node->next = next; \
/**/
void list_insert_before (list_s * next, list_s * node)
{
list_s * prev = next->prev;
LIST_LINK
}
void list_insert_after (list_s * prev, list_s * node)
{
list_s * next = prev->next;
LIST_LINK
}
void list_remove (list_s * node)
{
list_s * prev = node->prev;
list_s * next = node->next;
prev->next = next;
next->prev = prev;
}