forked from MuhammeedAlaa/Simplified-OS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.c
62 lines (55 loc) · 1.02 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "queue.h"
qNode *newNode(int d)
{
qNode *temp = (qNode *)malloc(sizeof(qNode));
temp->data = d;
temp->next = NULL;
return temp;
}
queue initQueue()
{
queue q;
q.front = q.rear = NULL;
q.size = 0;
return q;
}
void pushQueue(queue *q, int k)
{
qNode *temp = newNode(k);
if (q->rear == NULL)
{
q->front = q->rear = temp;
q->size = q->size + 1;
return;
}
q->rear->next = temp;
q->rear = temp;
q->size = q->size + 1;
}
void popQueue(queue *q)
{
if (q->front == NULL)
return;
qNode *temp = q->front;
q->front = q->front->next;
if (q->front == NULL)
q->rear = NULL;
free(temp);
q->size = q->size - 1;
}
int front(queue *q)
{
if (q->front != NULL)
return q->front->data;
return -1;
};
int rear(queue *q)
{
if (q->rear != NULL)
return q->rear->data;
return -1;
};
int isEmptyQueue(queue *q)
{
return q->size == 0;
}