diff --git a/ASD_Task_4.depend b/ASD_Task_4.depend index a544662..a0b42a1 100644 --- a/ASD_Task_4.depend +++ b/ASD_Task_4.depend @@ -19,3 +19,23 @@ "player.h" +1583488722 source:c:\users\computer\documents\github\asd_task_4\main.cpp + "player.h" + "list.h" + + +1582815955 c:\users\computer\documents\github\asd_task_4\player.h + "list.h" + +1583486807 c:\users\computer\documents\github\asd_task_4\list.h + + + + +1583488247 source:c:\users\computer\documents\github\asd_task_4\player.cpp + "player.h" + + +1583487672 source:c:\users\computer\documents\github\asd_task_4\list.cpp + "list.h" + diff --git a/bin/Debug/ASD_Task_4.exe b/bin/Debug/ASD_Task_4.exe new file mode 100644 index 0000000..f7d1d53 Binary files /dev/null and b/bin/Debug/ASD_Task_4.exe differ diff --git a/list.cpp b/list.cpp index 847a957..a66080e 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; + next(P) = NULL; + prev(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,17 @@ 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) = P; + prev(P) = P; + first(L) = 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 +60,14 @@ void insertLast(List &L, address P) { * FS : elemen yang ditunjuk P menjadi elemen terakhir pada List L */ //------------- YOUR CODE HERE ------------- - + if (first(L) == NULL){ + insertFirst(L,P); + } else { + next(P) = first(L); + prev(P) = prev(first(L)); + next(prev(first(L))) = P; + prev(first(L)) = P; + } //---------------------------------------- } @@ -60,7 +80,13 @@ address findElmByID(List L, infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- - + P = first(L); + do { + P = next(P); + } while (P != first(L) && info(P).ID != x.ID); + if (P == first(L) && info(P).ID != x.ID){ + return NULL; + } //---------------------------------------- return P; } @@ -74,7 +100,13 @@ address findElmByName(List L, infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- - + P = first(L); + do { + P = next(P); + } while (P != first(L) && info(P).name != x.name); + if (P == first(L) && info(P).name != x.name){ + return NULL; + } //---------------------------------------- return P; } @@ -85,7 +117,19 @@ 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) == NULL){ + P = first(L); + next(P) = NULL; + prev(P) = NULL; + first(L) = NULL; + } else { + P = first(L); + first(L) = next(P); + prev(first(L)) = prev(P); + next(prev(P)) = first(L); + next(P) = NULL; + prev(P) = NULL; + } //---------------------------------------- } @@ -95,7 +139,15 @@ void deleteLast(List &L, address &P) { * FS : elemen tarakhir di dalam List L dilepas dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + if (first(L) == NULL){ + deleteFirst(L,P); + } else { + P = prev(first(L)); + next(prev(P)) = first(L); + prev(first(L)) = prev(P); + next(P) = NULL; + prev(P) = NULL; + } //---------------------------------------- } @@ -106,7 +158,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,7 +176,15 @@ void deleteAfter(List &L, address &Prec, address &P) { * dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + if (next(Prec) == first(L)){ + deleteFirst(L,P); + } else { + P = next(Prec); + prev(next(P)) = Prec; + next(Prec) = next(P); + next(P) = NULL; + prev(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..9b71a27 100644 --- a/main.cpp +++ b/main.cpp @@ -125,7 +125,8 @@ void runMenu(int menu) { 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..f9f601f 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..63f561b 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..d9f7340 Binary files /dev/null and b/obj/Debug/player.o differ diff --git a/player.cpp b/player.cpp index 31ef288..cefeb1b 100644 --- a/player.cpp +++ b/player.cpp @@ -1,7 +1,7 @@ #include "player.h" #include -int randomInt(int max_int) { +int randomInt(int max_int) { /** YOU DON'T NEED TO MODIFY THIS */ srand(time(NULL)); return (rand() % max_int) + 1; @@ -43,8 +43,25 @@ void shuffleList(List &L) { * FS : isi (elemen) dari list teracak */ //------------- YOUR CODE HERE ------------- - - cout<<"UNDER MAIN TENIS"< 0) { + P = first(L); + int i = randomInt(total); + while (i != 0){ + P = next(P); + i--; + } + address Q = P; + deleteAfter(L,prev(P),Q); + insertFirst(L,Q); + total--; + } + cout<<"UNDER MAIN TENIS"<