diff --git a/ASD_Task_4.depend b/ASD_Task_4.depend index a544662..709df9f 100644 --- a/ASD_Task_4.depend +++ b/ASD_Task_4.depend @@ -19,3 +19,23 @@ "player.h" +1583592724 source:d:\std\github\asd_task_4\list.cpp + "list.h" + +1583514475 d:\std\github\asd_task_4\list.h + + + + +1583522349 source:d:\std\github\asd_task_4\player.cpp + "player.h" + + +1582640754 d:\std\github\asd_task_4\player.h + "list.h" + +1583592461 source:d:\std\github\asd_task_4\main.cpp + "player.h" + "list.h" + + diff --git a/bin/Debug/ASD_Task_4.exe b/bin/Debug/ASD_Task_4.exe new file mode 100644 index 0000000..81ab131 Binary files /dev/null and b/bin/Debug/ASD_Task_4.exe differ diff --git a/list.cpp b/list.cpp index 847a957..ad9f400 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,12 @@ address allocate(infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- - + P=new elmlist; + info(P).ID = x.ID; + info(P).location = x.location; + info(P).name = x.name; + next(P)=NULL; + prev(P)=NULL; //---------------------------------------- return P; } @@ -27,7 +32,7 @@ void deallocate(address &P) { * FS : menghapus elemen yang ditunjuk oleh P (delete) */ //------------- YOUR CODE HERE ------------- - + delete P; //---------------------------------------- } @@ -37,7 +42,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)=first(L); + prev(P)=prev(first(L)); + next(prev(first(L)))=P; + prev(first(L))=P; + first(L)=P; + }else { + first(L)=P; + next(P)=P; + prev(P)=P; + } //---------------------------------------- } @@ -47,7 +62,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 +82,9 @@ address findElmByID(List L, infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- - + while(next(P)!=first(L) && info(P).ID!=x.ID){ + P=next(P); + } //---------------------------------------- return P; } @@ -74,7 +98,9 @@ address findElmByName(List L, infotype x) { address P = NULL; //------------- YOUR CODE HERE ------------- - + while(next(P)!=first(L) && info(P).name!=x.name){ + P=next(P); + } //---------------------------------------- return P; } @@ -85,7 +111,16 @@ void deleteFirst(List &L, address &P) { * FS : elemen pertama di dalam List L dilepas dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + if(next(P)==first(L)){ + P=first(L); + next(P)=NULL; + prev(P)=NULL; + first(L)=NULL; + } else { + next(prev(first(L)))=next(P); + first(L)=next(P); + next(prev(first(L)))=first(L); + } //---------------------------------------- } @@ -95,7 +130,16 @@ void deleteLast(List &L, address &P) { * FS : elemen tarakhir di dalam List L dilepas dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + P=first(L); + if(next(P)==P){ + deleteFirst(L, P); + } else { + first(L)=next(first(L)); + next(prev(P))=first(L); + prev(first(L))=prev(P); + next(P)=NULL; + prev(P)=NULL; + } //---------------------------------------- } @@ -106,7 +150,10 @@ void insertAfter(List &L, address &Prec, address P) { * ditunjuk pointer Prec */ //------------- YOUR CODE HERE ------------- - + next(P)=next(Prec); + prev(next(P))=P; + next(Prec)=P; + prev(next(Prec))=Prec; //---------------------------------------- } @@ -117,7 +164,9 @@ void deleteAfter(List &L, address &Prec, address &P) { * dan disimpan/ditunjuk oleh P */ //------------- YOUR CODE HERE ------------- - + P=next(Prec); + next(Prec)=next(P); + next(prev(first(L)))=first(L); //---------------------------------------- } 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..801ddcf 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"<>x.ID; + P=findElmByID(L, x); + if(P!=NULL) { + cout<<"music found"<0) { + P=first(L); + while (j!=0){ + P=next(P); + j--; + } + address Prec=P; + deleteAfter(L, prev(P), Prec); + insertFirst(L, Prec); + i--; + } cout<<"UNDER MAIN TENIS"<