-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list.c
More file actions
49 lines (39 loc) · 787 Bytes
/
linked_list.c
File metadata and controls
49 lines (39 loc) · 787 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
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
struct node *next;
void *data;
} node;
typedef struct test {
unsigned int one;
char two[255];
char *three;
int four;
} test;
inline void insertafter(node *old, node *new) {
new->next = old->next;
old->next = new;
}
inline void cleanup(node *n) {
node *next = n->next;
if(n->data != NULL) {
free(n->data);
}
free(n);
if(next != NULL) {
cleanup(next);
}
}
int main(void) {
test *t1;
node *head, *tmp;
t1 = (test *)malloc(sizeof(test));
head = (node *) malloc(sizeof(node));
head->next = NULL;
head->data = t1;
tmp = (node *) malloc(sizeof(node));
tmp->data = NULL;
insertafter(head, tmp);
cleanup(head);
return 0;
}