view src/queue_test.c @ 10:68f85ffc6029

Finished rbtree. Reworked the iterators in list. Minor tweaks to others.
author Eris Caffee <discordia@eldalin.com>
date Fri, 28 Sep 2012 18:24:53 -0500
parents e117c4d93602
children
line source
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "queue.h"
6 #define MAX 10
8 int main(int argc, char**argv)
9 {
10 int i, j;
11 int *ip;
12 struct queue * q;
14 q = queue_new(MAX);
15 if (NULL == q)
16 {
17 perror("queue_new");
18 exit(EXIT_FAILURE);
19 }
21 // Fill the queue
22 for (i=0; i < MAX; i++)
23 {
24 ip = malloc(sizeof(int));
25 *ip = i;
26 if (NULL == queue_push(q, (void *) ip))
27 {
28 printf("queue_push failed\n");
29 free(ip);
30 }
31 }
33 // remove 5 items
34 printf("queue size is %zd\n", queue_size(q));
35 for (j=0; j < 5 && NULL != (ip = queue_pop(q)); j++)
36 {
37 printf("%d\n", *ip);
38 free(ip);
39 }
40 printf("queue size is %zd\n", queue_size(q));
42 // Overfill the queue
43 for (i=MAX; i < 2*MAX; i++)
44 {
45 ip = malloc(sizeof(int));
46 *ip = i;
47 if (NULL == queue_push(q, (void *) ip))
48 {
49 printf("queue_push failed\n");
50 free(ip);
51 }
52 }
54 // Empty the queue
55 printf("queue size is %zd\n", queue_size(q));
56 while (NULL != (ip = queue_pop(q)))
57 {
58 printf("%d\n", *ip);
59 free(ip);
60 }
61 printf("queue size is %zd\n", queue_size(q));
63 queue_delete(q);
65 exit(EXIT_SUCCESS);
66 }