3 #define MAX_QUEUE_SIZE 16
10 struct data data
[MAX_QUEUE_SIZE
];
15 static void queue_init(struct queue
*queue
)
17 queue
->first
= queue
->last
= 0;
20 static int queue_empty(const struct queue
*queue
)
22 return queue
->first
== queue
->last
;
25 static int queue_insert(struct queue
*queue
, struct data
*data
)
27 if (queue
->last
== MAX_QUEUE_SIZE
)
30 queue
->data
[queue
->last
] = *data
;
36 static int queue_remove(struct queue
*queue
, struct data
*ret
)
40 if (queue_empty(queue
))
44 *ret
= queue
->data
[queue
->first
];
47 for (i
= queue
->first
; i
< queue
->last
; i
++)
48 queue
->data
[i
] = queue
->data
[i
+ 1];
53 static void queue_print(const struct queue
*queue
)
57 if (queue_empty(queue
))
60 for (i
= queue
->first
; i
< queue
->last
; i
++)
61 printf("%d ", queue
->data
[i
].code
);
65 static void fill_data(struct data
*data
, int code
)
73 struct data data1
, data2
, data3
, data_ret
;
77 if (queue_empty(&queue
))
78 printf("Queue is empty\n");
80 printf("Queue is not empty\n");
86 queue_insert(&queue
, &data1
);
87 queue_insert(&queue
, &data2
);
88 queue_insert(&queue
, &data3
);
90 if (queue_empty(&queue
))
91 printf("Queue is empty\n");
93 printf("Queue is not empty\n");
97 queue_remove(&queue
, &data_ret
);
98 printf("Item removed: %d\n", data_ret
.code
);