-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue.c
More file actions
46 lines (41 loc) · 686 Bytes
/
queue.c
File metadata and controls
46 lines (41 loc) · 686 Bytes
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
#include<stdlib.h>
#include"queue.h"
void qinit(queue *q) {
q->head = q->tail = NULL;
q->c = 0;
}
void enqueue(queue *q, int n) {
qnode *temp;
temp = (qnode *)malloc(sizeof(qnode));
temp->number = n;
temp->next = q->head;
temp->prev = NULL;
q->c++;
if(q->tail == NULL)
q->tail = temp;
else
q->head->prev = temp;
q->head = temp;
}
int dequeue(queue *q) {
int nn;
qnode *temp2;
q->c--;
nn = q->tail->number;
temp2 = q->tail;
if(q->tail == q->head) {
q->tail = NULL;
q->head = NULL;
} else {
q->tail = q->tail->prev;
q->tail->next = NULL;
}
free(temp2);
return nn;
}
int qisfull(queue *q) {
return 0;
}
int qisempty(queue *q) {
return q->c == 0;
}