-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueuearray.h
47 lines (41 loc) · 933 Bytes
/
queuearray.h
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
38
39
40
41
42
43
44
45
46
47
#define MAXQUEUE 4
#define TRUE 1
#define FALSE 0
typedef struct queue
{
int a[MAXQUEUE];
int front;
int rear;
}Q;
// function prototypes
void initQueue(Q *); // initializing the queue
void append(Q *, int, int *); // enqueue an integer to the queue
void serve(Q *, int *, int *); // dequeue an element out of the queue
// function definitions
// initializing the queue
void initQueue(Q *pQueue)
{
pQueue->front = pQueue->rear = -1;
}
// enqueue an integer to the queue
void append(Q *pQueue,int toAppend,int *overflow)
{
if(pQueue->rear==MAXQUEUE-1)
*overflow = TRUE;
else
{
*overflow = FALSE;
pQueue->a[++(pQueue->rear)] = toAppend;
}
}
// dequeue an element out of the queue
void serve(Q *pQueue,int *served,int *underflow)
{
if(pQueue->front==pQueue->rear)
*underflow = TRUE;
else
{
*underflow = FALSE;
*served = pQueue->a[++(pQueue->front)];
}
}