-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_test.c
45 lines (34 loc) · 930 Bytes
/
list_test.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 <stdio.h>
#include "list.h"
struct list_node_t {
struct list_t q;
int data;
};
static void
list_print(const char *msg, struct list_t *lst) {
printf("\nlist:%s\n", msg);
while ((lst = lst->next)) {
struct list_node_t *node = container_of(lst, struct list_node_t, q);
printf("%d-", node->data);
}
}
int main() {
struct list_t lst;
list_init(&lst);
list_print("1", &lst);
struct list_node_t *node = malloc(sizeof(struct list_node_t));
node->data = 1;
list_init(&node->q);
list_insert_after(&lst, &node->q);
node = malloc(sizeof(struct list_node_t));
node->data = 2;
list_init(&node->q);
list_insert_after(&lst, &node->q);
node = malloc(sizeof(struct list_node_t));
node->data = 3;
list_init(&node->q);
list_insert_after(&lst, &node->q);
list_print("2", &lst);
list_del(&node->q);
list_print("3", &lst);
}