-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
60 lines (46 loc) · 1.05 KB
/
queue.cpp
File metadata and controls
60 lines (46 loc) · 1.05 KB
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
#include "queue.h"
void enqueue(List &L, address p){
//memasukan sebuah node ke barisan list
address Q = L.tail;
if(Q != NULL){
Q->next = p;
L.tail = p;
} else {
L.head = p;
L.tail = p;
}
}
address dequeue(List &L){
//mengeluakan node dari barisan list
/*
IS. Terdefinisi sebuah list L (L tidak kosong dan mungkin berisi satu elemen).
FS. P berisi alamat elmList yang pertama, elmList yang ditunjuk oleh P dihapus dari
list
*/
address P;
P = L.head;
if((L.head)->next == NULL){
L.head = NULL;
} else {
L.head = (L.head)->next;
};
P->next = NULL;
return P;
}
void printQueue(List &L){
//mengeluarkan semua isi barisan list
/*
IS. Terdefinisi sebuah list L
FS. Menampilkan semua info elmList di list.
*/
address P;
if(L.head == NULL){
cout << "List kosong!" << endl;
} else {
P = L.head;
while(P != NULL){
cout<< P->info <<endl;
P = P->next;
};
}
}