summaryrefslogtreecommitdiff
path: root/lib/test_list.c
blob: 7e72fb80bd993a5ab440d9f1e2e19faab913393f (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
#include "doublelinkedlist.h"
#include <stdlib.h>
#include <stdio.h>


struct in {
	int low;
	int max;
	struct list next;
};

int main()
{
	struct in tmp;
	struct in tmp2;
	struct in tmp3;
	struct in tmp4;
	struct list *iter, *head;

	tmp.low = 1;
	tmp.max = 3;
	tmp2.low = 5;
	tmp2.max = 9;
	tmp3.low = 14;
	tmp3.max = 16;
	tmp4.low = 23;
	tmp4.max = 35;

	LIST_INIT(&tmp.next);
	LIST_INIT(&tmp2.next);
	LIST_INIT(&tmp3.next);
	LIST_INIT(&tmp4.next);

	list_insert_after(&tmp.next, &tmp2.next);
	list_insert_after(&tmp2.next, &tmp3.next);
	list_insert_after(&tmp3.next, &tmp4.next);

	head = &tmp2.next;

	LIST_TO_END(iter, head) {
		struct in *i = CONTAINER_OF(iter, struct in, next);
		printf("low: %i, max: %i\n", i->low, i->max);
	}

	list_delete(&tmp4.next);
	LIST_TO_END(iter, head) {
		struct in *i = CONTAINER_OF(iter, struct in, next);
		printf("low: %i, max: %i\n", i->low, i->max);
	}

}