-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_barang.cpp
125 lines (115 loc) · 2.65 KB
/
list_barang.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "list_barang.h"
adrBarang alokasiBarang(infotype x){
adrBarang P = new elmBarang;
info(P) = x;
next(P) = NULL;
return P;
}
adrBarang findElm(listBarang L, infotype x){
if(first(L) == NULL){
cout << "List Barang Kosong!" << endl;
return NULL;
}else{
adrBarang P = first(L);
while(P != NULL){
if(info(P) == x){
return P;
}
P = next(P);
}
}
return NULL;
}
void printInfo(listBarang L){
if(first(L) == NULL){
cout << "List Kosong!" << endl;
}else{
adrBarang P = first(L);
int i = 1;
cout << " == Data Barang == " << endl;
while(P != NULL) {
cout << i << ". " << info(P) << "." << endl;
P = next(P);
i++;
}
cout << endl;
}
}
void createList(listBarang &L){
first(L) = NULL;
last(L) = NULL;
}
void insertFirst(listBarang &L, adrBarang P){
if(first(L) == NULL){
first(L) = P;
last(L) = P;
}else{
next(P) = first(L);
first(L) = P;
}
}
void insertAfter(listBarang &L, adrBarang Prec, adrBarang P){
if(Prec = NULL){
cout<<"Tidak ditemukan."<< endl;
} else {
next(P) = next(Prec);
next(Prec) = P;
}
}
void insertLast(listBarang &L, adrBarang P){
if(first(L) == NULL){
first(L) = P;
last(L) = P;
}else{
next(last(L)) = P;
last(L) = P;
next(P) = NULL;
}
}
void deleteFirst(listBarang &L, adrBarang &P){
if(first(L) == NULL){
cout << "List Kosong!" << endl;
}else if(next(first(L)) == NULL){
first(L) = NULL;
last(L) = NULL;
}else{
P = first(L);
first(L) = next(P);
info(P) = "";
next(P) = NULL;
}
}
void deleteLast(listBarang &L, adrBarang &P){
if(first(L) == NULL){
cout << "List Kosong!" << endl;
}else if(next(first(L)) == NULL){
first(L) = NULL;
last(L) = NULL;
}else{
P = last(L);
adrBarang Q = first(L);
while(next(Q) != last(L)){
Q = next(Q);
}
next(Q) = NULL;
last(L) = Q;
info(P) = "";
next(P) = NULL;
}
}
void deleteAfter(listBarang &L, adrBarang Prec, adrBarang &P){
if(Prec == NULL){
cout << "Tidak Ditemukan!" << endl;
}else if(next(Prec) == NULL){
cout << "Tidak Ada Data Untuk Dihapus!" << endl;
}else{
P = Prec;
Prec = first(L);
while(next(Prec) != P){
Prec = next(Prec);
}
next(Prec) = next(P);
next(P) = NULL;
info(P) = "";
}
}