ee30a22bbea95eac31a2ac1f467eca3c3e7a7825
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VP_SDK / Examples / linux / atcodec_sorted_list.c
1
2 #include <stdio.h>
3
4 #include "VP_Os/vp_os_types.h"
5 #include "ATcodec/ATcodec_Sorted_List.h"
6
7 void print_element(void *element)
8 {
9   printf("%d, ", *(uint32_t *)element);
10 }
11
12 void print_list(ATcodec_Sorted_List_t *list)
13 {
14   printf("{ ");
15   ATcodec_Sorted_List_batchProcess(list, print_element);
16   printf("}\n");
17 }
18
19 #define INSERT(VALUE) \
20   element = VALUE; \
21   ATcodec_Sorted_List_insertElement(&list, &element, element); \
22   print_list(&list)
23
24 #define REMOVE(INDEX) \
25   ATcodec_Sorted_List_removeElement(&list, ATcodec_Sorted_List_getElement(&list, INDEX)); \
26   print_list(&list)
27
28 int main(int argc, char **argv)
29 {
30   ATcodec_Sorted_List_t list;
31   int element;
32
33   ATcodec_Sorted_List_init(&list, sizeof(int));
34   print_list(&list);
35
36   INSERT(10);
37   INSERT(5);
38   INSERT(7);
39   INSERT(12);
40   INSERT(1);
41
42   REMOVE(3);
43
44   INSERT(12);
45
46   REMOVE(0);
47   REMOVE(0);
48
49   INSERT(3);
50   INSERT(4);
51   INSERT(6);
52
53   REMOVE(0);
54   REMOVE(0);
55   REMOVE(0);
56   REMOVE(0);
57   REMOVE(0);
58   REMOVE(0);
59
60   INSERT(7);
61   INSERT(12);
62   INSERT(1);
63
64   REMOVE(1);
65   REMOVE(1);
66   REMOVE(0);
67
68   ATcodec_Sorted_List_destroy(&list);
69
70   return EXIT_SUCCESS;
71 }