/
abv_list.c
45 lines (39 loc) · 967 Bytes
/
abv_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
37
38
39
40
41
42
43
44
45
#include <stdlib.h>
#include "abv_list.h"
ABV_NODE* create_new_end_node(ABV const* abv)
{
ABV_NODE *node = malloc(sizeof(ABV_NODE));
set_abv(node, abv);
set_next(node, NULL);
return node;
}
void enumerate(ABV_LIST* list, ABV_ENUMERATE_FUNC func) {
ABV_NODE *current = list;
while (current != NULL) {
func(¤t->abv);
current = (ABV_NODE *)get_next(current);
}
}
ABV_LIST* create_list(ABV const* abv)
{
return create_new_end_node(abv);
}
void destroy_list(ABV_LIST* list)
{
ABV_NODE *head = list;
ABV_NODE *current = head;
while (head != NULL) {
head = (ABV_NODE *)get_next(head);
free(current);
current = head;
}
}
void extend_list(ABV_LIST* list, ABV const* abv)
{
ABV_NODE *current = list;
while (get_next(current) != NULL) {
current = (ABV_NODE *)get_next(current);
}
ABV_NODE *node = create_new_end_node(abv);
set_next(current, node);
}