|
| 1 | +#include <iostream> |
| 2 | +#include <stdlib.h> |
| 3 | +#include "singlelist.h" |
| 4 | + |
| 5 | +using namespace std; |
| 6 | + |
| 7 | +int main() { |
| 8 | + List L; |
| 9 | + address P, Q; |
| 10 | + infotype X, Y; |
| 11 | + |
| 12 | + cout<<endl; |
| 13 | + cout<<"Hello, Selamat Datang di Single Linked List"<< endl; |
| 14 | + cout <<""<<endl; |
| 15 | + |
| 16 | + |
| 17 | + cout<<"1a. Uji project berikut: Allocation dan Deallocation"<<endl; |
| 18 | + X = 10; |
| 19 | + P = allocate(X); |
| 20 | + cout<<" print X = "<<X<<endl; |
| 21 | + cout<<" P = allocate(X)"<<endl; |
| 22 | + cout<<" print info(P) = "<<info(P)<<endl; |
| 23 | + cout<<" print alamat dari elemen P = "<<P<<endl; |
| 24 | + cout<<""<<endl; |
| 25 | + cout<<" [Tekan enter untuk lanjut]"<<endl; |
| 26 | + cin.get(); |
| 27 | + cout<<" deallocate(P)"<<endl; |
| 28 | + deallocate(P); |
| 29 | + /** cout<<" print info(P) = "<<info(P)<<endl; // this will cause error */ |
| 30 | + cout<<" print alamat dari elemen P = "<<P<<endl; |
| 31 | + cout<<" [press enter to continue]"<<endl; |
| 32 | + cin.get();system("cls"); |
| 33 | + cout<<endl; |
| 34 | + cout<<"1b. Ujilah project berikut: Create List dan Print Info"<<endl; |
| 35 | + createList(L); |
| 36 | + cout<<" Ujilah Print Info untuk List L"<<endl; |
| 37 | + printInfo(L); |
| 38 | + cout<<" anda bisa memodifikasi prosedur printInfo(List L) untuk menampilkan pesan"<<endl |
| 39 | + <<" saat list kosong"<<endl; |
| 40 | + cout<<" [Tekan enter untuk lanjut]"<<endl; |
| 41 | + cin.get();system("cls"); |
| 42 | + cout<<endl; |
| 43 | + |
| 44 | + |
| 45 | + cout<<"2. Uji prosedur insertFirst(List &L, address P)"<<endl; |
| 46 | + createList(L); |
| 47 | + cout<<" Initial list [kosong]: "; printInfo(L); |
| 48 | + cout<<endl; |
| 49 | + cout<<" Insert First info = 5"<<endl; |
| 50 | + insertFirst(L, allocate(5)); |
| 51 | + cout<<" Isi list seharusnya : 5, "<<endl; |
| 52 | + cout<<" List anda : "; printInfo(L); |
| 53 | + cout<<endl; |
| 54 | + cout<<" Insert First info = 8"<<endl; |
| 55 | + insertFirst(L, allocate(8)); |
| 56 | + cout<<" Isi list seharusnya : 8, 5, "<<endl; |
| 57 | + cout<<" List anda : "; printInfo(L); |
| 58 | + cout<<endl; |
| 59 | + cout<<" Insert First info = 0"<<endl; |
| 60 | + insertFirst(L, allocate(0)); |
| 61 | + cout<<" Isi list seharusnya : 0, 8, 5, "<<endl; |
| 62 | + cout<<" List anda : "; printInfo(L); |
| 63 | + cout<<endl; |
| 64 | + cout<<" Insert First info = 3"<<endl; |
| 65 | + insertFirst(L, allocate(3)); |
| 66 | + cout<<" Isi list seharusnya : 3, 0, 8, 5, "<<endl; |
| 67 | + cout<<" List anda : "; printInfo(L); |
| 68 | + cout<<" [Tekan enter untuk lanjut]"<<endl; |
| 69 | + cin.get();system("cls"); |
| 70 | + cout<<endl; |
| 71 | + |
| 72 | + |
| 73 | + cout<<"3. Uji prosedur deleteFirst(List &L, address &P)"<<endl; |
| 74 | + cout<<" ** Anda mungkin mendapat error pada bagian ini**"<<endl; |
| 75 | + cout<<" ** pikirlah mengapa hal tersebut dapat terjadi, kemudian tanyakan asprak anda **"<<endl<<endl; |
| 76 | + cout<<" Initial List: "; printInfo(L); |
| 77 | + cout<<endl; |
| 78 | + cout<<" Delete First"<<endl; deleteFirst(L, P); |
| 79 | + cout<<" Info(P) seharusnya : 3"<<endl; |
| 80 | + cout<<" Info(P) anda : "<<info(P)<<endl; |
| 81 | + cout<<" List seharusnya : 0, 8, 5, "<<endl; |
| 82 | + cout<<" List anda : "; printInfo(L); |
| 83 | + deallocate(P); |
| 84 | + cout<<endl; |
| 85 | + cout<<" Delete First"<<endl; deleteFirst(L, P); |
| 86 | + cout<<" Info(P) seharusnya : 0"<<endl; |
| 87 | + cout<<" Info(P) anda : "<<info(P)<<endl; |
| 88 | + cout<<" List seharusnya : 8, 5, "<<endl; |
| 89 | + cout<<" List anda : "; printInfo(L); |
| 90 | + deallocate(P); |
| 91 | + cout<<endl; |
| 92 | + cout<<" [Tekan enter untuk lanjut]"<<endl; |
| 93 | + cin.get();system("cls"); |
| 94 | + cout<<endl; |
| 95 | + |
| 96 | + |
| 97 | + cout<<"3. Uji prosedur deleteFirst(List &L, address &P) [Cont'd]"<<endl; |
| 98 | + cout<<" Initial List: "; printInfo(L); |
| 99 | + cout<<endl; |
| 100 | + cout<<" Delete First"<<endl; deleteFirst(L, P); |
| 101 | + cout<<" Info(P) seharusnya : 8"<<endl; |
| 102 | + cout<<" Info(P) anda : "<<info(P)<<endl; |
| 103 | + cout<<" List seharusnya : 5, "<<endl; |
| 104 | + cout<<" List anda : "; printInfo(L); |
| 105 | + deallocate(P); |
| 106 | + cout<<endl; |
| 107 | + cout<<" Delete First"<<endl; deleteFirst(L, P); |
| 108 | + cout<<" Info(P) seharusnya : 5"<<endl; |
| 109 | + cout<<" Info(P) anda : "<<info(P)<<endl; |
| 110 | + cout<<" List seharusnya : [kosong] "<<endl; |
| 111 | + cout<<" List anda : "; printInfo(L); |
| 112 | + deallocate(P); |
| 113 | + cout<<endl; |
| 114 | + cout<<" Delete First"<<endl; |
| 115 | + cout<<" prosedur anda harus mengecek apakah list kosong"<<endl; |
| 116 | + deleteFirst(L, P); |
| 117 | + cout<<" address P seharusnya : 0 (NULL)"<<endl; |
| 118 | + cout<<" address P anda : "<<P<<endl; |
| 119 | + cout<<" List seharusnya : [kosong] "<<endl; |
| 120 | + cout<<" List anda : "; printInfo(L); |
| 121 | + cout<<endl; |
| 122 | + cout<<" [Tekan enter untuk lanjut]"<<endl; |
| 123 | + cin.get();system("cls"); |
| 124 | + cout<<endl; |
| 125 | + |
| 126 | + |
| 127 | + cout<<"4. Uji prosedur insertLast(List &L, address P)"<<endl; |
| 128 | + cout<<" ** Anda mungkin mendapat error pada bagian ini**"<<endl; |
| 129 | + cout<<" ** pikirlah mengapa hal tersebut dapat terjadi, kemudian tanyakan asprak anda **"<<endl<<endl; |
| 130 | + createList(L); |
| 131 | + cout<<" Initial List [kosong]: "; printInfo(L); |
| 132 | + cout<<endl; |
| 133 | + cout<<" Insert Last info = 5"<<endl; |
| 134 | + cout<<" prosedur anda harus mengecek apakah list kosong"<<endl; |
| 135 | + insertLast(L, allocate(5)); |
| 136 | + cout<<" List seharusnya : 5, "<<endl; |
| 137 | + cout<<" List anda : "; printInfo(L); |
| 138 | + cout<<endl; |
| 139 | + cout<<" Insert Last info = 8"<<endl; |
| 140 | + insertLast(L, allocate(8)); |
| 141 | + cout<<" List seharusnya : 5, 8, "<<endl; |
| 142 | + cout<<" List anda : "; printInfo(L); |
| 143 | + cout<<endl; |
| 144 | + cout<<" Insert Last info = 0"<<endl; |
| 145 | + insertLast(L, allocate(0)); |
| 146 | + cout<<" List seharusnya : 5, 8, 0, "<<endl; |
| 147 | + cout<<" List anda : "; printInfo(L); |
| 148 | + cout<<endl; |
| 149 | + cout<<" Insert Last info = 3"<<endl; |
| 150 | + insertLast(L, allocate(3)); |
| 151 | + cout<<" List seharusnya : 5, 8, 0, 3, "<<endl; |
| 152 | + cout<<" List anda : "; printInfo(L); |
| 153 | + cout<<" [Tekan enter untuk lanjut]"<<endl; |
| 154 | + cin.get();system("cls"); |
| 155 | + cout<<endl; |
| 156 | + |
| 157 | + |
| 158 | + cout<<"5. Test the procedure deleteLast(List &L, address &P)"<<endl; |
| 159 | + cout<<" ** Anda mungkin mendapat error pada bagian ini**"<<endl; |
| 160 | + cout<<" ** pikirlah mengapa hal tersebut dapat terjadi, kemudian tanyakan asprak anda **"<<endl<<endl; |
| 161 | + cout<<" Initial List: "; printInfo(L); |
| 162 | + cout<<endl; |
| 163 | + cout<<" Delete Last"<<endl; deleteLast(L, P); |
| 164 | + cout<<" Info(P) seharusnya : 3"<<endl; |
| 165 | + cout<<" Info(P) anda : "<<info(P)<<endl; |
| 166 | + cout<<" List seharusnya : 5, 8, 0, "<<endl; |
| 167 | + cout<<" List anda : "; printInfo(L); |
| 168 | + deallocate(P); |
| 169 | + cout<<endl; |
| 170 | + cout<<" Delete Last"<<endl; deleteLast(L, P); |
| 171 | + cout<<" Info(P) seharusnya : 0"<<endl; |
| 172 | + cout<<" Info(P) anda : "<<info(P)<<endl; |
| 173 | + cout<<" List seharusnya : 5, 8, "<<endl; |
| 174 | + cout<<" List anda : "; printInfo(L); |
| 175 | + deallocate(P); |
| 176 | + cout<<endl; |
| 177 | + cout<<" [Tekan enter untuk lanjut]"<<endl; |
| 178 | + cin.get();system("cls"); |
| 179 | + cout<<endl; |
| 180 | + |
| 181 | + |
| 182 | + cout<<"5. Test the procedure deleteLast(List &L, address &P) [Cont'd]"<<endl; |
| 183 | + cout<<" Initial List: "; printInfo(L); |
| 184 | + cout<<endl; |
| 185 | + cout<<" Delete Last"<<endl; deleteLast(L, P); |
| 186 | + cout<<" Info(P) seharusnya : 8"<<endl; |
| 187 | + cout<<" Info(P) anda : "<<info(P)<<endl; |
| 188 | + cout<<" List seharusnya : 5, "<<endl; |
| 189 | + cout<<" List anda : "; printInfo(L); |
| 190 | + deallocate(P); |
| 191 | + cout<<endl; |
| 192 | + cout<<" Delete Last"<<endl; deleteLast(L, P); |
| 193 | + cout<<" Info(P) seharusnya : 5"<<endl; |
| 194 | + cout<<" Info(P) anda : "<<info(P)<<endl; |
| 195 | + cout<<" List seharusnya : [kosong] "<<endl; |
| 196 | + cout<<" List anda : "; printInfo(L); |
| 197 | + deallocate(P); |
| 198 | + cout<<endl; |
| 199 | + cout<<" Delete Last"<<endl; |
| 200 | + cout<<" prosedur anda harus mengecek apakah list kosong"<<endl; |
| 201 | + deleteLast(L, P); |
| 202 | + cout<<" address P seharusnya: 0 (NULL)"<<endl; |
| 203 | + cout<<" address P anda : "<<P<<endl; |
| 204 | + cout<<" List seharusnya : [kosong] "<<endl; |
| 205 | + cout<<" List anda : "; printInfo(L); |
| 206 | + cout<<endl; |
| 207 | + cout<<" [Tekan enter untuk lanjut]"<<endl; |
| 208 | + cin.get();system("cls"); |
| 209 | + cout<<endl; |
| 210 | + |
| 211 | + |
| 212 | + cout<<"Anda telah menyelesaikan jurnal modul 2"<<endl; |
| 213 | + cout<<endl; |
| 214 | + cout<<"BONUS: Reverse List"<<endl; |
| 215 | + cout<<"Amati prosedur reverseList yang telah tersedia, amati hasil dibawah:"<<endl; |
| 216 | + createList(L); |
| 217 | + insertFirst(L,allocate(3)); |
| 218 | + insertFirst(L,allocate(6)); |
| 219 | + insertFirst(L,allocate(8)); |
| 220 | + insertFirst(L,allocate(2)); |
| 221 | + insertFirst(L,allocate(9)); |
| 222 | + cout<<"sebelum reverse : ";printInfo(L); |
| 223 | + reverseList(L); |
| 224 | + cout<<"setelah reverse : ";printInfo(L); |
| 225 | + |
| 226 | + cout<<""<<endl; |
| 227 | + return 0; |
| 228 | +} |
| 229 | + |
0 commit comments