-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfcode_list.c
More file actions
76 lines (55 loc) · 1.1 KB
/
fcode_list.c
File metadata and controls
76 lines (55 loc) · 1.1 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>
#include "fcode_list.h"
node *list_add(node *list, void *value) {
node *n;
node *idx;
n = (node *)malloc(sizeof(node));
n->value = value;
n->next = NULL;
if (list == NULL) {
return n;
}
idx = list;
while (idx->next != NULL) {
idx = idx->next;
}
idx->next = n;
return list;
}
node *list_search(node *list, void *value) {
node *idx;
idx = list;
while (idx) {
if (idx->value == value)
return idx;
idx = idx->next;
}
return NULL;
}
node *list_del(node *list, node *n) {
node *idx;
if (list == n) {
node *ret = list->next;
free(list);
return ret;
}
idx = list;
while (idx->next) {
if (idx->next == n) {
idx->next = idx->next->next;
free(n);
return list;
}
idx = idx->next;
}
return list;
}
void list_print(node *list, void (*print)(void *a)) {
node *idx;
idx = list;
while(idx) {
print(idx->value);
idx = idx->next;
}
}