-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueLinked.c
54 lines (46 loc) · 863 Bytes
/
QueueLinked.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
#include <stdio.h>
#include <stdlib.h>
#include "QueueLinked.h"
void CreateQueue(Queue *pq){
pq->front = NULL;
pq->rear = NULL;
pq ->size = 0;
}
int QueueEmpty(Queue *pq){
return pq->front == NULL;
}
int QueueFull(Queue *pq){
return 0;
}
void Enqueue(QueueEntry item,Queue *pq){
QueueNode *p = (QueueNode *) malloc(sizeof(QueueNode));
p ->entry = item;
p ->next = NULL;
if(!pq->rear)
pq ->front = p;
else
pq->rear->next = p;
pq ->rear = p;
pq->size++;
}
void Dequeue(QueueEntry *item,Queue *pq){
QueueNode *p;
p = pq->front;
*item = p->entry;
pq->front = p -> next;
if(!pq->front)
pq ->rear = NULL;
free(p);
pq->size--;
}
void ClearQueue(Queue *pq){
while(pq->front){
pq->rear = pq->front->next;
free(pq->front);
pq->front = pq->rear;
}
pq ->size = 0;
}
int QueueSize(Queue * pq){
return pq->size;
}