aboutsummaryrefslogtreecommitdiff
path: root/tests/test91.c
blob: 8c8f63e48c73c78e48e138a50b570a3be68f775c (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
#include <stdio.h>
#include "utlist.h"

typedef struct el {
    int id, score;
    struct el *next, *prev;
} el;

static int order_desc(el *a, el *b)
{
    return (a->score > b->score) ? -1 : (a->score < b->score);
}

int main()
{
    int i;
    el *head = NULL;
    el els[15], *e;

    for (i=0; i<15; i++) {
        els[i].id = (int)'a'+i;
        els[i].score = i%7;
        LL_INSERT_INORDER(head, &els[i], order_desc);
    }
    LL_FOREACH(head, e) {
        printf("%c ", e->id);
    }
    printf("\n");

    printf("DL_INSERT_INORDER\n");
    head = NULL;
    for (i=0; i<15; i++) {
        DL_INSERT_INORDER(head, &els[i], order_desc);
    }
    DL_FOREACH(head, e) {
        printf("%c ", e->id);
    }
    printf("\n");

    printf("CDL_INSERT_INORDER\n");
    head = NULL;
    for (i=0; i<15; i++) {
        CDL_INSERT_INORDER(head, &els[i], order_desc);
    }
    CDL_FOREACH(head, e) {
        printf("%c ", e->id);
    }
    printf("\n");
    CDL_FOREACH2(head, e, prev) {
        printf("%c ", e->id);
    }
    printf("\n");
    return 0;
}