forked from abunai59/umouse2013
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.c
38 lines (33 loc) · 758 Bytes
/
queue.c
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
// A looped array queue
#include <stdbool.h>
#include <stdlib.h>
#include "queue.h"
void init_queue(Queue * queue) {
if(queue != NULL) {
queue->head = 0;
queue->tail = 0;
}
}
void q_push(Queue * q, Cell * cellptr) {
if(q != NULL && cellptr != NULL) {
q->element[q->tail] = cellptr;
q->tail++;
if (q->tail >= MAX_ELEMENT) q->tail = 0;
}
}
Cell * q_pop(Queue * q) {
if(q != NULL) {
Cell * result = q->element[q->head];
q->head++;
if (q->head >= MAX_ELEMENT) q->head = 0;
return result;
}
else return NULL;
}
bool is_empty(Queue * q){
if(q != NULL) {
if(q->head == q->tail) return true;
else return false;
}
else return true;
}