diff --git a/ASD_Task_4.depend b/ASD_Task_4.depend index a544662..9d67f55 100644 --- a/ASD_Task_4.depend +++ b/ASD_Task_4.depend @@ -19,3 +19,23 @@ "player.h" +1583587627 source:d:\tugas kuliah\github\asd_task-4\asd_task_4\main.cpp + "player.h" + "list.h" + + +1583496536 d:\tugas kuliah\github\asd_task-4\asd_task_4\player.h + "list.h" + +1583587651 d:\tugas kuliah\github\asd_task-4\asd_task_4\list.h + + + + +1583587775 source:d:\tugas kuliah\github\asd_task-4\asd_task_4\list.cpp + "list.h" + +1583587795 source:d:\tugas kuliah\github\asd_task-4\asd_task_4\player.cpp + "player.h" + + diff --git a/ASD_Task_4.layout b/ASD_Task_4.layout index 5ec49e7..20eafdc 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..7564b93 Binary files /dev/null and b/bin/Debug/ASD_Task_4.exe differ diff --git a/list.cpp b/list.cpp index 847a957..c7d2fc1 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; //---------------------------------------- } @@ -17,7 +17,10 @@ address allocate(infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- - + P = new elmlist; + info(P) = x; + prev(P) = NULL; + next(P) = NULL; //---------------------------------------- return P; } @@ -27,7 +30,7 @@ void deallocate(address &P) { * FS : menghapus elemen yang ditunjuk oleh P (delete) */ //------------- YOUR CODE HERE ------------- - + delete P; //---------------------------------------- } @@ -37,7 +40,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) + { + first(L) = P; + prev(P) = P; + next(P) = P; + } + else + { + next(P) = first(L); + prev(P) = prev(first(L)); + next(prev(first(L))) = P; + prev(first(L)) = P; + first(L) = P; + } //---------------------------------------- } @@ -47,7 +63,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) + { + first(L) = P; + prev(P) = P; + next(P) = P; + } + else + { + next(P) = first(L); + prev(P) = prev(first(L)); + next(prev(first(L))) = P; + prev(first(L)) = P; + } //---------------------------------------- } @@ -60,7 +88,15 @@ address findElmByID(List L, infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- - + P = first(L); + while (P!= first(L) && info(P).ID != x.ID) + { + P = next(P); + } + if (P == first(L) && info(P).ID != x.ID) + { + P = NULL; + } //---------------------------------------- return P; } @@ -74,7 +110,15 @@ address findElmByName(List L, infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- - + P = first(L); + while (P!= first(L) && info(P).name != x.name) + { + P = next(P); + } + if (P == first(L) && info(P).name != x.name) + { + P = NULL; + } //---------------------------------------- return P; } @@ -85,7 +129,21 @@ void deleteFirst(List &L, address &P) { * FS : elemen pertama di dalam List L dilepas dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + if (first(L) = next(first(L))) + { + P = first(L); + next(P) = NULL; + prev(P) = NULL; + } + else + { + P = first(L); + first(L) = next(P); + next(prev(P)) = prev(P); + prev(next(P)) = first(L); + next(P) = NULL; + prev(P) = NULL; + } //---------------------------------------- } @@ -95,7 +153,12 @@ void deleteLast(List &L, address &P) { * FS : elemen tarakhir di dalam List L dilepas dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + address Q = first(L); + P = prev(Q); + next(prev(P)) = Q; + prev(Q) = prev(P); + next(P) = NULL; + prev(P) = NULL; //---------------------------------------- } @@ -106,7 +169,10 @@ void insertAfter(List &L, address &Prec, address P) { * ditunjuk pointer Prec */ //------------- YOUR CODE HERE ------------- - + prev(next(Prec)) = Prec; + next(P) = next(Prec); + next(Prec) = P; + prev(P) = Prec; //---------------------------------------- } @@ -117,7 +183,17 @@ void deleteAfter(List &L, address &Prec, address &P) { * dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + if (Prec = first(L)) + { + deleteFirst(L,P); + } + else + { + next(Prec) = next(P); + prev(next(P)) = Prec; + prev(P) = NULL; + next(P) = NULL; + } //---------------------------------------- } diff --git a/list.h b/list.h index 4468d0f..6b8bc21 100644 --- a/list.h +++ b/list.h @@ -29,14 +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..7888e5a 100644 --- a/main.cpp +++ b/main.cpp @@ -122,10 +122,8 @@ void runMenu(int menu) { case 2: // insert last music //------------- YOUR CODE HERE ------------- - cout<<"UNDER MAIN TENIS"<>x.ID; + P = findElmByID(L,x); + if(P != NULL) + { + cout<<"Music found"< 0) + { + P = first(L); + int rand = randomInt(Count); + while (rand != 0) + { + P = next(P); + rand = rand - 1; + } + address Q; + deleteAfter(L, prev(P), Q); + insertFirst(L,Q); + Count = Count - 1; + } //---------------------------------------- } @@ -55,9 +73,21 @@ void playRepeat(List &L, int n) { * dari lagu pertama hingga terakhir sebanyak n kali */ //------------- YOUR CODE HERE ------------- - - cout<<"UNDER MAIN TENIS"<