blob: 226985e48e1524fab1298f713b669a58177f5f89 (
plain)
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
55
56
57
58
59
60
61
|
/*
* src/list.c
* (c) 2021 Jonas Gunz <himself@jonasgunz.de>
* License: MIT
*/
#include "list.h"
int list_add( list_element_t** _root, void* _data ) {
list_element_t** iter = _root;
list_element_t* new_element = malloc( sizeof(list_element_t) );
if( !new_element )
return 1;
new_element->data = _data;
new_element->next = NULL;
while(*iter)
iter = & (*iter)->next;
*iter = new_element;
return 0;
}
int list_sort ( list_element_t** _root ) {
return -1;
}
int list_length ( list_element_t** _root ) {
list_element_t** iter = _root;
int ret = 0;
if( !_root )
return -1;
while(*iter) {
ret ++;
iter = & (*iter)->next;
}
return ret;
}
void* list_pop_front ( list_element_t** _root ) {
list_element_t* old = NULL;
void* old_data = NULL;
if( !*_root )
return NULL;
old = *_root;
old_data = old->data;
*_root = (*_root)->next;
free ( old );
return old_data;
}
|