diff --git a/ASD_Task_4.depend b/ASD_Task_4.depend index a544662..051d328 100644 --- a/ASD_Task_4.depend +++ b/ASD_Task_4.depend @@ -19,3 +19,23 @@ "player.h" +1583583634 source:c:\users\asus\documents\github\asd_task_4\main.cpp + "player.h" + "list.h" + + +1583583634 c:\users\asus\documents\github\asd_task_4\player.h + "list.h" + +1583583603 c:\users\asus\documents\github\asd_task_4\list.h + + + + +1583583634 source:c:\users\asus\documents\github\asd_task_4\player.cpp + "player.h" + + +1583584162 source:c:\users\asus\documents\github\asd_task_4\list.cpp + "list.h" + diff --git a/ASD_Task_4.layout b/ASD_Task_4.layout index 5ec49e7..b31b4aa 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..81b5e06 Binary files /dev/null and b/bin/Debug/ASD_Task_4.exe differ diff --git a/list.cpp b/list.cpp index 847a957..cc11c3d 100644 --- a/list.cpp +++ b/list.cpp @@ -5,6 +5,7 @@ void createList(List &L) { * FS : first(L) diset Nil */ //------------- YOUR CODE HERE ------------- + L.first=NULL; //---------------------------------------- } @@ -17,6 +18,10 @@ address allocate(infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- + P=new elmlist; + P->info=x; + P->next=NULL; + P->prev=NULL; //---------------------------------------- return P; @@ -27,6 +32,7 @@ void deallocate(address &P) { * FS : menghapus elemen yang ditunjuk oleh P (delete) */ //------------- YOUR CODE HERE ------------- + delete P; //---------------------------------------- } @@ -37,6 +43,17 @@ void insertFirst(List &L, address P) { * FS : elemen yang ditunjuk P menjadi elemen pertama pada List L */ //------------- YOUR CODE HERE ------------- + if (L.first==NULL){ + L.first=P; + P->next=P; + P->prev=P; + }else { + P->next=L.first; + P->prev=L.first->prev; + L.first->prev->next=P; + L.first->prev=P; + L.first=P; + } //---------------------------------------- } @@ -47,6 +64,16 @@ void insertLast(List &L, address P) { * FS : elemen yang ditunjuk P menjadi elemen terakhir pada List L */ //------------- YOUR CODE HERE ------------- + if (L.first==NULL){ + L.first=P; + P->next=P; + P->prev=P; + }else { + P->next=L.first; + P->prev=L.first->prev; + L.first->prev->next=P; + L.first->prev=P; + } //---------------------------------------- } @@ -60,7 +87,12 @@ address findElmByID(List L, infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- - + if(L.first!=NULL){ + P=L.first; + while(P!=NULL && P->info.ID!=x.ID){ + P=P->next; + } + } //---------------------------------------- return P; } @@ -74,7 +106,13 @@ address findElmByName(List L, infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- - + P=L.first; + if(L.first!=NULL){ + P=L.first; + while(P!=NULL && P->info.name!=x.name){ + P=P->next; + } + } //---------------------------------------- return P; } @@ -85,7 +123,17 @@ void deleteFirst(List &L, address &P) { * FS : elemen pertama di dalam List L dilepas dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + P=L.first; + if (L.first==L.first->next){ + P->next=NULL; + P->prev=NULL; + }else if (L.first!=NULL){ + L.first=L.first->next; + P->prev->next=L.first; + L.first->prev=P->prev; + P->next=NULL; + P->prev=NULL; + } //---------------------------------------- } @@ -95,7 +143,17 @@ void deleteLast(List &L, address &P) { * FS : elemen tarakhir di dalam List L dilepas dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + if (P->next==L.first){ + P=L.first; + P->next=NULL; + P->prev=NULL; + }else if (L.first!=NULL){ + P=L.first->prev; + P->prev->next=L.first; + L.first->prev=P->prev; + P->next=NULL; + P->prev=NULL; + } //---------------------------------------- } @@ -106,6 +164,14 @@ void insertAfter(List &L, address &Prec, address P) { * ditunjuk pointer Prec */ //------------- YOUR CODE HERE ------------- + if (L.first == NULL){ + insertFirst(L,P); + }else { + P->next=Prec->next; + P->prev=Prec; + Prec->next->prev=P; + Prec->next=P; + } //---------------------------------------- @@ -118,6 +184,18 @@ void deleteAfter(List &L, address &Prec, address &P) { */ //------------- YOUR CODE HERE ------------- + P=Prec->next; + if (Prec->next != L.first){ + Prec->next=P->next; + P->next->prev=Prec; + P->next=NULL; + P->prev=NULL; + } else { + P->next=NULL; + P->prev=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..1940e9a 100644 --- a/main.cpp +++ b/main.cpp @@ -122,7 +122,8 @@ void runMenu(int menu) { case 2: // insert last music //------------- YOUR CODE HERE ------------- - cout<<"UNDER MAIN TENIS"<prev; + playMusic(P); + cout<<"press enter";getche(); //---------------------------------------- break; @@ -154,6 +157,8 @@ void runMenu(int menu) { P = findElmByName(L, x); if(P != NULL){ cout<<"music found"<prev; + playMusic(P); + } //---------------------------------------- break; diff --git a/obj/Debug/list.o b/obj/Debug/list.o new file mode 100644 index 0000000..889c42c 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..41f3fa9 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..5c8ed1a Binary files /dev/null and b/obj/Debug/player.o differ diff --git a/player.cpp b/player.cpp index 31ef288..8180f76 100644 --- a/player.cpp +++ b/player.cpp @@ -44,8 +44,27 @@ void shuffleList(List &L) { */ //------------- YOUR CODE HERE ------------- - cout<<"UNDER MAIN TENIS"<next ; + i++ ; + } + while (P != first(L)) ; + while (i > 0){ + P = L.first ; + k = randomInt(i) ; + while (k != 0) + { + P = P->next ; + k-- ; + } + Q = P ; + deleteAfter(L,P->prev,Q) ; + insertFirst(L,Q) ; + i-- ; + } //---------------------------------------- } @@ -55,8 +74,16 @@ void playRepeat(List &L, int n) { * dari lagu pertama hingga terakhir sebanyak n kali */ //------------- YOUR CODE HERE ------------- - - cout<<"UNDER MAIN TENIS"<next; + } + while(P != L.first); + i++; + } //---------------------------------------- } @@ -70,7 +97,19 @@ void deleteMusicByID(List &L, infotype x) { */ //------------- YOUR CODE HERE ------------- - cout<<"UNDER MAIN TENIS"<prev){ + deleteLast(L,P); + deallocate(P); + }else if (P!=NULL){ + Q=P->prev; + deleteAfter(L,Q,P); + deallocate(P); + } //----------------------------------------