31 |
|
|
32 |
|
|
33 |
node_t * |
node_t * |
34 |
node_create(void *data) |
node_create(void) |
35 |
{ |
{ |
36 |
node_t *node = xcalloc(sizeof *node); |
node_t *node = xcalloc(sizeof *node); |
|
|
|
|
node->data = data; |
|
|
|
|
37 |
return node; |
return node; |
38 |
} |
} |
39 |
|
|
40 |
|
void |
41 |
|
node_free(node_t *node) |
42 |
|
{ |
43 |
|
xfree(node); |
44 |
|
} |
45 |
|
|
46 |
node_t * |
node_t * |
47 |
list_add(list_t *list, node_t *node) |
list_add(void *data, node_t *node, list_t *list) |
48 |
{ |
{ |
49 |
|
node->data = data; |
50 |
node->prev = NULL; |
node->prev = NULL; |
51 |
node->next = list->head; |
node->next = list->head; |
52 |
|
|
63 |
} |
} |
64 |
|
|
65 |
node_t * |
node_t * |
66 |
list_remove(list_t *list, node_t *node) |
list_remove(node_t *node, list_t *list) |
67 |
{ |
{ |
68 |
/* Assumption: If node->next == NULL, then list->tail == node |
/* Assumption: If node->next == NULL, then list->tail == node |
69 |
* and: If node->prev == NULL, then list->head == node |
* and: If node->prev == NULL, then list->head == node |
85 |
} |
} |
86 |
|
|
87 |
/* Set this to NULL does matter */ |
/* Set this to NULL does matter */ |
88 |
node->next = node->prev = NULL; |
node->next = NULL; |
89 |
|
node->prev = NULL; |
90 |
list->elements--; |
list->elements--; |
91 |
|
|
92 |
return node; |
return node; |
93 |
} |
} |
|
|
|
|
void |
|
|
node_free(node_t *node) |
|
|
{ |
|
|
xfree(node); |
|
|
} |
|