diff --git a/ASD_Task_4.depend b/ASD_Task_4.depend index a544662..30a6ed4 100644 --- a/ASD_Task_4.depend +++ b/ASD_Task_4.depend @@ -19,3 +19,23 @@ "player.h" +1583390485 source:d:\kuliah\semester 2\asd_task_4\player.cpp + "player.h" + + +1582637257 d:\kuliah\semester 2\asd_task_4\player.h + "list.h" + +1582637384 d:\kuliah\semester 2\asd_task_4\list.h + + + + +1583390998 source:d:\kuliah\semester 2\asd_task_4\list.cpp + "list.h" + +1583391176 source:d:\kuliah\semester 2\asd_task_4\main.cpp + "player.h" + "list.h" + + diff --git a/ASD_Task_4.layout b/ASD_Task_4.layout index 5ec49e7..94c2957 100644 --- a/ASD_Task_4.layout +++ b/ASD_Task_4.layout @@ -2,29 +2,29 @@ - + - + - + - + - + - + - + - + - + - + diff --git a/bin/Debug/ASD_Task_4.exe b/bin/Debug/ASD_Task_4.exe new file mode 100644 index 0000000..bf60807 Binary files /dev/null and b/bin/Debug/ASD_Task_4.exe differ diff --git a/list.cpp b/list.cpp index 847a957..3828c3f 100644 --- a/list.cpp +++ b/list.cpp @@ -5,7 +5,7 @@ void createList(List &L) { * FS : first(L) diset Nil */ //------------- YOUR CODE HERE ------------- - + first(L)=NULL; //---------------------------------------- } @@ -15,9 +15,11 @@ address allocate(infotype x) { * next dan prev elemen = Nil */ - address P = NULL; + address P = new elmlist; //------------- YOUR CODE HERE ------------- - + info(P) = x; + next(P) = NULL; + prev(P) = NULL; //---------------------------------------- return P; } @@ -27,7 +29,7 @@ void deallocate(address &P) { * FS : menghapus elemen yang ditunjuk oleh P (delete) */ //------------- YOUR CODE HERE ------------- - + delete P; //---------------------------------------- } @@ -37,7 +39,20 @@ void insertFirst(List &L, address P) { * FS : elemen yang ditunjuk P menjadi elemen pertama pada List L */ //------------- YOUR CODE HERE ------------- - + if (first(L)!=NULL) + { + next(P) = first(L); + prev(P) = prev(first(L)); + next(prev(first(L))) = P; + prev(first(L)) = P; + first(L) = P; + } + else + { + first(L) = P; + next(first(L)) = P; + prev(first(L)) = P; + } //---------------------------------------- } @@ -47,7 +62,19 @@ void insertLast(List &L, address P) { * FS : elemen yang ditunjuk P menjadi elemen terakhir pada List L */ //------------- YOUR CODE HERE ------------- - + if (first(L)!=NULL) + { + next(P) = first(L); + prev(P) = prev(first(L)); + next(prev(first(L))) = P; + prev(first(L)) = P; + } + else + { + first(L)=P; + next(first(L)) = P; + prev(first(L)) = P; + } //---------------------------------------- } @@ -58,11 +85,16 @@ address findElmByID(List L, infotype x) { mengembalikan Nil jika tidak ditemukan */ - address P = NULL; + address P = first(L); //------------- YOUR CODE HERE ------------- - + do{ + P=next(P); + }while(P!=first(L) && info(P).ID != x.ID); + if (info(P).ID == x.ID){ + return P; + } //---------------------------------------- - return P; + return NULL; } address findElmByName(List L, infotype x) { @@ -72,11 +104,18 @@ address findElmByName(List L, infotype x) { mengembalikan Nil jika tidak ditemukan */ - address P = NULL; + address P = first(L); //------------- YOUR CODE HERE ------------- - + do + { + P = next(P); + } while (P != first(L)&& info(P).name != x.name); + if (info(P).name == x.name) + { + return P; + } //---------------------------------------- - return P; + return NULL; } void deleteFirst(List &L, address &P) { @@ -85,7 +124,18 @@ void deleteFirst(List &L, address &P) { * FS : elemen pertama di dalam List L dilepas dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + P = first(L); + if (next(first(L))!=P){ + first(L) = next(P); + next(prev(P)) = first(L); + prev(first(L)) = prev(P); + next(P) = NULL; + prev(P) = NULL; + }else{ + next(P)=NULL; + prev(P)=NULL; + first(L)=NULL; + } //---------------------------------------- } @@ -95,8 +145,12 @@ void deleteLast(List &L, address &P) { * FS : elemen tarakhir di dalam List L dilepas dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - - //---------------------------------------- + P = prev(first(L)); + next(prev(P))=first(L); + prev(first(L)) = prev(prev(P)); + next(P) = NULL; + prev(P) = NULL; + //--------------------- } void insertAfter(List &L, address &Prec, address P) { @@ -106,7 +160,14 @@ void insertAfter(List &L, address &Prec, address P) { * ditunjuk pointer Prec */ //------------- YOUR CODE HERE ------------- - + if(first(L)==NULL){ + insertFirst(L,P); + }else{ + next(P) = next(Prec); + prev(P) = Prec; + prev(next(Prec)) = P; + next(Prec) = P; + } //---------------------------------------- } @@ -117,6 +178,17 @@ void deleteAfter(List &L, address &Prec, address &P) { * dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- + P = next(Prec); + if(next(Prec)!=first(L)){ + next(Prec) = next(P); + prev(next(P)) = Prec; + next(P) = NULL; + prev(P) = NULL; + }else{ + next(P)=NULL; + prev(P)=NULL; + P=NULL; + } //---------------------------------------- } diff --git a/list.h b/list.h index 4468d0f..08a59e0 100644 --- a/list.h +++ b/list.h @@ -29,15 +29,15 @@ typedef struct elmlist *address; struct elmlist { //------------- YOUR CODE HERE ----------- - - + infotype info; + address next; + address prev; //---------------------------------------- }; struct List { //------------- YOUR CODE HERE ----------- - - + address first; //---------------------------------------- }; diff --git a/main.cpp b/main.cpp index a66a5c1..89c0f91 100644 --- a/main.cpp +++ b/main.cpp @@ -117,13 +117,17 @@ void runMenu(int menu) { // insert first music P = inputMusic(); insertFirst(L,P); - cout<<"press enter";getche(); + cout<<"press enter"; + getche(); break; case 2: // insert last music //------------- YOUR CODE HERE ------------- cout<<"UNDER MAIN TENIS"<>x.ID; + P = findElmByID(L, x); + if(P != NULL){ + cout<<"music found"<>x.name; + cin>>x.ID; deleteMusicByID(L, x); cout<<"press enter";getche(); break; diff --git a/obj/Debug/list.o b/obj/Debug/list.o new file mode 100644 index 0000000..3a4bd35 Binary files /dev/null and b/obj/Debug/list.o differ diff --git a/obj/Debug/main.o b/obj/Debug/main.o new file mode 100644 index 0000000..26d3b88 Binary files /dev/null and b/obj/Debug/main.o differ diff --git a/obj/Debug/player.o b/obj/Debug/player.o new file mode 100644 index 0000000..8dfb8e8 Binary files /dev/null and b/obj/Debug/player.o differ diff --git a/player.cpp b/player.cpp index 31ef288..c8692a6 100644 --- a/player.cpp +++ b/player.cpp @@ -14,12 +14,16 @@ void printInfo(List L) { */ address Q = first(L); - do { - cout<<"name : "<