-
Notifications
You must be signed in to change notification settings - Fork 2
/
list.h
33 lines (28 loc) · 1.29 KB
/
list.h
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
#define DLLIST_INIT_NODE(L) \
do{ \
(L)->prev = NULL; \
(L)->next = NULL; \
}while(0)
#define DLLIST_ADD_AFTER(NODE_TYPE, N1, N2) \
do{ \
NODE_TYPE* prev_next = (N1)->next; \
(N1)->next = N2; \
(N2)->next = prev_next; \
if (prev_next != NULL) { prev_next->prev = N2; } \
(N2)->prev = N1; \
}while(0)
#define DLLIST_ADD_BEFORE(NODE_TYPE, N1, N2) \
do{ \
NODE_TYPE* prev_prev = (N1)->prev; \
(N1)->prev = N2; \
(N2)->prev = prev_prev; \
if (prev_prev != NULL) { prev_prev->next = N2; } \
(N2)->next = N1; \
}while(0)
#define DLLIST_REMOVE(NODE_TYPE, N) \
do{ \
NODE_TYPE* prev_prev = (N)->prev; \
NODE_TYPE* prev_next = (N)->next; \
if (prev_prev != NULL) { prev_prev->next = prev_next; } \
if (prev_next != NULL) { prev_next->prev = prev_prev; } \
}while(0)