-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.cpp
102 lines (86 loc) · 1.66 KB
/
queue.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<iostream>
#include"queue.h"
bool isEmptyQ(Queue Q){
if(head(Q) == NULL && tail(Q)==NULL){
return true;
}else{
return false;
}
}
void createQ(Queue &Q){
head(Q) = NULL;
tail(Q) = NULL;
}
void createNewElmtQ(string ID,int waktu,addressQ &P){
P = new elmQ;
ID(P) = ID;
waktu(P) = waktu;
next(P) = NULL;
}
void enqueue(Queue &Q,addressQ P)
{
if(isEmptyQ(Q))
{
head(Q) = P;
tail(Q) = P;
}
else
{
next(tail(Q)) = P;
tail(Q) = P;
}
}
void dequeue(Queue &Q,addressQ &P)
{
if(!isEmptyQ(Q))
{
P = head(Q);
if(head(Q) == tail(Q))
{
head(Q) = NULL;
tail(Q) = NULL;
}
else
{
head(Q) = next(head(Q));
next(P) = NULL;
}
}
else{
P = NULL;
}
}
void soal3()
{
Queue Q; addressQ W;
createQ(Q);
createNewElmtQ("T25", 13, W);
enqueue(Q, W);
createNewElmtQ("T1", 4, W);
enqueue(Q, W);
createNewElmtQ("T11", 5, W);
enqueue(Q, W);
createNewElmtQ("T21", 21, W);
enqueue(Q, W);
createNewElmtQ("T8", 3, W);
enqueue(Q, W);
addressQ R;
while(!isEmptyQ(Q)){
dequeue(Q, W);
if (waktu(W)>5){
waktu(W) = waktu(W)-5;
enqueue(Q, W);
}
R = head(Q);
if (!isEmptyQ(Q)){
cout<<"Antrian saat ini :";
while (R!=NULL){
cout<<" ID : "<<ID(R)<<" waktu: "<<waktu(R)<<" ";
R = next(R);
}
cout<<endl;
} else{
cout<<"Antrian sudah kosong"<<endl;
}
}
}