-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.c
More file actions
55 lines (40 loc) · 856 Bytes
/
list.c
File metadata and controls
55 lines (40 loc) · 856 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// list.c -- list helper functions.
//
#include <stdio.h>
#include <assert.h>
#include "list.h"
void listInit( linked_list_t* list )
{
assert(list);
list->first = list->last = NULL;
return;
}
void listAdd( linked_list_t* list, link_t* item )
{
assert(list);
assert(item);
item->next = item->prev = NULL;
if (list->last)
{
// Non-empty list, item added to the tail
((link_t *)list->last)->next = item;
item->prev = (link_t *)list->last;
list->last = (link_t *)item;
}
else
{
// Empty list, single item added
list->first = item;
list->last = item;
}
return;
}
void listIterate( linked_list_t* list, iter_callback_t callback )
{
link_t* link;
assert(list);
for (link = list->first ; link ; link = link->next) {
callback( (link_t*)link );
}
return;
}