view src/queue_test.c @ 1:392ce56806f9

Added dequeue, cmake file, fix copypasta in queue
author Eris Caffee <discordia@eldalin.com>
date Thu, 20 Sep 2012 23:11:40 -0500
parents 5af32066927f
children e117c4d93602
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 perror("queue_push");
28 }
30 // remove 5 items
31 printf("queue size is %zd\n", queue_size(q));
32 for (j=0; j < 5 && NULL != (ip = queue_pop(q)); j++)
33 {
34 printf("%d\n", *ip);
35 free(ip);
36 }
37 printf("queue size is %zd\n", queue_size(q));
39 // Overfill the queue
40 for (i=MAX; i < 2*MAX; i++)
41 {
42 ip = malloc(sizeof(int));
43 *ip = i;
44 if (NULL == queue_push(q, (void *) ip))
45 perror("queue_push");
46 }
48 // Empty the queue
49 printf("queue size is %zd\n", queue_size(q));
50 while (NULL != (ip = queue_pop(q)))
51 {
52 printf("%d\n", *ip);
53 free(ip);
54 }
55 printf("queue size is %zd\n", queue_size(q));
57 queue_delete(q);
59 exit(EXIT_SUCCESS);
60 }