-
Notifications
You must be signed in to change notification settings - Fork 2
/
Queue.c
73 lines (65 loc) · 1.09 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
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "Queue.h"
queue Makequeue()
{
queue Q = (queue)malloc(sizeof(Node));
Q->Next = NULL;
Q->Prev = NULL;
return Q;
}
void push(PtrToNode T, ElementType y)
{
PtrToNode Tmp, L;
Tmp = Makequeue();
L = T->Prev;
Tmp->x = y;
Tmp->Next = T;
Tmp->Prev = L;
L->Next = Tmp;
T->Prev = Tmp;
}
void pop(PtrToNode H)
{
PtrToNode Tmp, L;
Tmp = H->Next;
if (Tmp->Next == NULL)
{
printf("The queue is Empty");
return;
}
L = Tmp->Next;
H->Next = L;
L->Prev = H;
Tmp->Next = NULL;
Tmp->Prev = NULL;
}
bool empty(PtrToNode H)
{
if (H->Next->Next == NULL)
{
return true;
}
else
{
return false;
}
}
PtrToNode front(PtrToNode H)
{
return H->Next;
}
PtrToNode back(PtrToNode T)
{
return T->Prev;
}
void Freequeue(PtrToNode H, PtrToNode T)
{
while (H->Next != T)
{
pop(H);
}
free(H);
free(T);
}