diff --git a/Multi_IIIB/Multi_IIIB.depend b/Multi_IIIB/Multi_IIIB.depend index 54a2955..e439f69 100644 --- a/Multi_IIIB/Multi_IIIB.depend +++ b/Multi_IIIB/Multi_IIIB.depend @@ -46,3 +46,48 @@ 1485554288 source:c:\users\andityaarifianto\documents\github\asd_multilist\multi_iii\list_relasi.cpp "list_relasi.h" +1524910999 source:c:\users\aldi\desktop\prog\std\multi_iiib\list_child.cpp + "list_child.h" + "list_relasi.h" + +1524758566 c:\users\aldi\desktop\prog\std\multi_iiib\list_child.h + + +1524919065 source:c:\users\aldi\desktop\prog\std\multi_iiib\list_parent.cpp + "list_parent.h" + +1524643156 c:\users\aldi\desktop\prog\std\multi_iiib\list_parent.h + + "list_relasi.h" + +1524881689 c:\users\aldi\desktop\prog\std\multi_iiib\list_relasi.h + "list_relasi.h" + "list_child.h" + + +1524915346 source:c:\users\aldi\desktop\prog\std\multi_iiib\list_relasi.cpp + "list_relasi.h" + +1524922218 source:c:\users\aldi\desktop\prog\std\multi_iiib\main.cpp + + + + + + "list_child.h" + "list_parent.h" + "operation.h" + +1524921707 source:c:\users\aldi\desktop\prog\std\multi_iiib\operation.cpp + "operation.h" + +1524921658 c:\users\aldi\desktop\prog\std\multi_iiib\operation.h + "list_child.h" + "list_parent.h" + "list_relasi.h" + + + + + + diff --git a/Multi_IIIB/Multi_IIIB.layout b/Multi_IIIB/Multi_IIIB.layout index f2243bb..ffa3ac8 100644 --- a/Multi_IIIB/Multi_IIIB.layout +++ b/Multi_IIIB/Multi_IIIB.layout @@ -2,34 +2,39 @@ - + - + - + - + - + - + - + - + - + - + - + - + + + + + + diff --git a/Multi_IIIB/README.md b/Multi_IIIB/README.md new file mode 100644 index 0000000..d0682aa --- /dev/null +++ b/Multi_IIIB/README.md @@ -0,0 +1,72 @@ +# Task_5 [2017/2018-II] +Task 5 : Circular Double Linked List + +# DEADLINE = FEBRUARY 24TH, 2018 - 23:59 + +## Reading Material +* [git cheat sheet](https://education.github.com/git-cheat-sheet-education.pdf) +* [markdown cheat sheet](https://enterprise.github.com/downloads/en/markdown-cheatsheet.pdf) + +## Workflow +1. FORK this repositori ASD_Task_5 to your GitHub account +2. CLONE ASD_Task_5 repository from YOUR OWN ACCOUNT +3. open and modify codes in *.cpp and *.h files inside project ASD_Task_5 +4. write your code inside the provided space in each functions/procedures +5. COMMIT and PUSH your project to your account +6. create a Pull Request + +Introduction to Double Circular Linked List
+Create a music player application to implement the double circular linked list data structure + +##library integration +1. on Code::Blocks, go into menu project->Build Option +2. go to Linker Settings tab +3. click Add to add new lib function +4. type winmm +5. click OK + +##list.h +modify the elemenList and List structure to implement Double Circular linked list + +##list.cpp +modify each function to fit the data structure +* createList +* allocate, deallocate +* insertFirst, insertLast, insertAfter +* deleteFirst, deleteLast, deleteAfter +* findElmByID, findElmByName +to implement Double Circular Linked List mechanism + +##player.cpp +these function are already defined: +* function to produce random integer
`int randomInt(int max_int);`
+* function to print music list inserted
`void printInfo(List L);`
+* function to play current music pointed by P
`void playMusic(address P);`
+
+TODO : +create function according to the header defined in player.h + +* function to sort the music list by ID
+ ``` void sortListByID(List &L); ```
+ +* function to play the music list from the first music and repeat the list n times
`void playRepeat(List &, int n);`
+ +* function to delete any music defined by its ID
+ ```void deleteMusicByID(List &L, infotype x);``` + +* function to shuffle the music list
`void shuffleList(List &);`
simple logic example:
+ +``` loop n times + P <- first + x = randomInt + for i to x, + move P to next element + delete after P + insert first P + ``` + + +##main.cpp +* modify the main menu progam +* run the application + diff --git a/Multi_IIIB/artist.h b/Multi_IIIB/artist.h new file mode 100644 index 0000000..e69de29 diff --git a/Multi_IIIB/asset/musik1.wav b/Multi_IIIB/asset/musik1.wav new file mode 100644 index 0000000..5d371e7 Binary files /dev/null and b/Multi_IIIB/asset/musik1.wav differ diff --git a/Multi_IIIB/asset/musik10.wav b/Multi_IIIB/asset/musik10.wav new file mode 100644 index 0000000..47d7696 Binary files /dev/null and b/Multi_IIIB/asset/musik10.wav differ diff --git a/Multi_IIIB/asset/musik11.wav b/Multi_IIIB/asset/musik11.wav new file mode 100644 index 0000000..9dac17b Binary files /dev/null and b/Multi_IIIB/asset/musik11.wav differ diff --git a/Multi_IIIB/asset/musik2.wav b/Multi_IIIB/asset/musik2.wav new file mode 100644 index 0000000..84c2031 Binary files /dev/null and b/Multi_IIIB/asset/musik2.wav differ diff --git a/Multi_IIIB/asset/musik3.wav b/Multi_IIIB/asset/musik3.wav new file mode 100644 index 0000000..dac777c Binary files /dev/null and b/Multi_IIIB/asset/musik3.wav differ diff --git a/Multi_IIIB/asset/musik4.wav b/Multi_IIIB/asset/musik4.wav new file mode 100644 index 0000000..7a46278 Binary files /dev/null and b/Multi_IIIB/asset/musik4.wav differ diff --git a/Multi_IIIB/asset/musik5.wav b/Multi_IIIB/asset/musik5.wav new file mode 100644 index 0000000..5e563aa Binary files /dev/null and b/Multi_IIIB/asset/musik5.wav differ diff --git a/Multi_IIIB/asset/musik6.wav b/Multi_IIIB/asset/musik6.wav new file mode 100644 index 0000000..436359a Binary files /dev/null and b/Multi_IIIB/asset/musik6.wav differ diff --git a/Multi_IIIB/asset/musik7.wav b/Multi_IIIB/asset/musik7.wav new file mode 100644 index 0000000..6b87f2b Binary files /dev/null and b/Multi_IIIB/asset/musik7.wav differ diff --git a/Multi_IIIB/asset/musik8.WAV b/Multi_IIIB/asset/musik8.WAV new file mode 100644 index 0000000..4e196ab Binary files /dev/null and b/Multi_IIIB/asset/musik8.WAV differ diff --git a/Multi_IIIB/asset/musik9.wav b/Multi_IIIB/asset/musik9.wav new file mode 100644 index 0000000..199d8c7 Binary files /dev/null and b/Multi_IIIB/asset/musik9.wav differ diff --git a/Multi_IIIB/bin/Debug/Multi_IIIB.exe b/Multi_IIIB/bin/Debug/Multi_IIIB.exe new file mode 100644 index 0000000..5934281 Binary files /dev/null and b/Multi_IIIB/bin/Debug/Multi_IIIB.exe differ diff --git a/Multi_IIIB/control.cpp b/Multi_IIIB/control.cpp new file mode 100644 index 0000000..053b52d --- /dev/null +++ b/Multi_IIIB/control.cpp @@ -0,0 +1,31 @@ +#include "control.h" + +void addArtist(List_parent LP, int i){ + infotype_parent x; + cout<<"Artis Name : ";cin>>x.name; + cout<<"Artist Genre : ";cin>>x.genre; + x.id = i++; + insertFirst(LP,alokasi(x)); +} + +void addSong(List_parent &LP, List_child &LC, List_relasi &LR){ + infotype_parent xp; + address_parent P = findElmName(LP,xp); + cout<<"Name Artist : ";cin>>xp.name; + + if(P==NULL){ + cout<<"Artist Not Exist"<info.name<<" founded. \n"; + cout<<"\n"; + cout<<"input name Song : ";cin>>xc.name_song; + cout<<"input location Song : ";cin>>xc.name_loc; + xc.id_song++; + address_child Pc = alokasi(xc); + address_relasi Pr = alokasi(Pc); + insertLast(LC,Pc); + insertLast(LR,Pr); + } + +} diff --git a/Multi_IIIB/control.h b/Multi_IIIB/control.h new file mode 100644 index 0000000..bd645e0 --- /dev/null +++ b/Multi_IIIB/control.h @@ -0,0 +1,14 @@ +#ifndef CONTROL_H_INCLUDED +#define CONTROL_H_INCLUDED +#include +#include "list_child.h" +#include "list_parent.h" +#include "list_relasi.h" + +using namespace std; + +void addArtist(List_parent LP); +void addSong(List_parent &LP, List_child &LC, List_relasi &LR); + + +#endif // CONTROL_H_INCLUDED diff --git a/Multi_IIIB/list_child.cpp b/Multi_IIIB/list_child.cpp index 33d09f9..bcbfe6e 100644 --- a/Multi_IIIB/list_child.cpp +++ b/Multi_IIIB/list_child.cpp @@ -1,11 +1,12 @@ #include "list_child.h" +#include "list_relasi.h" -void createList(List_child &L) { +void createList_C(List_child &L) { first(L) = NULL; last(L) = NULL; } -address_child alokasi(infotype_child x) { +address_child alokasi_C(infotype_child x) { address_child P = new elmlist_child; info(P) = x; next(P) = NULL; @@ -13,30 +14,145 @@ address_child alokasi(infotype_child x) { return P; } -void insertFirst(List_child &L, address_child P) { - if(first(L) == NULL) { - last(L) = P; - first(L) = P; - } else { - next(P) = first(L); - prev(first(L)) = P; - first(L) = P; +void insertFirst_C(List_child &L, address_child P) { + if(first(L)==NULL){ + first(L)=P; + last(L)=P; + next(last(L))=first(L); + prev(first(L))=last(L); + }else{ + next(P)=first(L); + first(L)=P; + next(last(L))=first(L); + prev(first(L))=last(L); } } -void printInfo(List_child L) { +void insertLast_C(List_child &L, address_child P){ + if(first(L)==NULL){ + first(L)=P; + last(L)=P; + next(last(L))=first(L); + prev(first(L))=last(L); + }else{ + next(last(L))=P; + next(P)=first(L); + prev(P)=last(L); + prev(first(L))=P; + last(L)=P; + } +} + +void insertAfter_C(List_child &L, address_child &Prec, address_child P){ + if(first(L)!=NULL){ + if(Prec!=NULL){ + if(Prec==last(L)){ + insertLast_C(L,P); + }else{ + next(P)=next(Prec); + prev(next(P))=P; + next(Prec)=P; + prev(P)=Prec; + } + } + } +} + +void deleteFirst_C(List_child &L, address_child &P){ + if(first(L)!=NULL){ + if(next(first(L))==first(L)){ + P = first(L); + first(L)=NULL; + last(L)=NULL; + }else{ + P = first(L); + prev(next(P))=last(L); + next(last(L))=next(P); + first(L)=next(P); + next(P)=NULL; + prev(P)=NULL; + } + //---------------------------------------- + } +} + +void deleteLast_C(List_child &L, address_child &P){ + if(first(L)!=NULL){ + if(next(first(L))==first(L)){ + deleteFirst_C(L,P); + }else{ + P = last(L); + prev(first(L))=prev(P); + next(prev(P))=first(L); + prev(P)=NULL; + next(P)=NULL; + + } + } +} +void deleteAfter_C(List_child &L, address_child Prec, address_child &P){ + if(first(L)!=NULL){ + if(Prec!=NULL){ + if(Prec==last(L)){ + deleteFirst_C(L,P); + }else if(next(Prec)==last(L)){ + deleteLast_C(L,P); + }else{ + P=next(Prec); + next(Prec)=next(P); + prev(next(P))=Prec; + next(P)=NULL; + prev(P)=NULL; + } + } + }else{ + cout<<"List Kosong"<"<info.id_song<info.name_song<info.name_loc<info.id_song == x.id_song){ + return P; + }else{ + P = next(P); + } + }while(next(P)!=first(L) && P->info.id_song != x.id_song); + + }else{ + return NULL; + } + if(P->info.id_song!=x.id_song){ + return NULL; + } + + + //---------------------------------------- + return P; +} + +address_child findNameSong(List_child L, infotype_child x) { address_child P = first(L); while(P != NULL) { - if(info(P)==x) { + if(P->info.name_song==x.name_song) { return P; } P = next(P); @@ -44,7 +160,7 @@ address_child findElm(List_child L, infotype_child x) { return NULL; } -void insertAfter(address_child &Prec, address_child P) { +void insertAfter_C(address_child &Prec, address_child P) { prev(next(Prec)) = P; next(P) = next(Prec); prev(P) = Prec; diff --git a/Multi_IIIB/list_child.h b/Multi_IIIB/list_child.h index e11826c..3b92051 100644 --- a/Multi_IIIB/list_child.h +++ b/Multi_IIIB/list_child.h @@ -11,7 +11,13 @@ using namespace std; #define last(L) L.last #define info(P) P->info -typedef string infotype_child; +struct song{ + int id_song; + string name_song; + string name_loc; +}; + +typedef song infotype_child; typedef struct elmlist_child *address_child; struct elmlist_child{ @@ -26,20 +32,20 @@ struct List_child{ }; /** TIDAK PERLU MODIFIKASI */ -void createList(List_child &L); -void insertFirst(List_child &L, address_child P); -void insertLast(List_child &L, address_child P); -void insertAfter(address_child Prec, address_child P); -void deleteFirst(List_child &L, address_child &P); -void deleteLast(List_child &L, address_child &P); -void deleteAfter(address_child Prec, address_child &P); +void createList_C(List_child &L); +void insertFirst_C(List_child &L, address_child P); +void insertLast_C(List_child &L, address_child P); +void insertAfter_C(List_child &L, address_child &Prec, address_child P); +void deleteFirst_C(List_child &L, address_child &P); +void deleteLast_C(List_child &L, address_child &P); +void deleteAfter_C(List_child &L, address_child Prec, address_child &P); /** PERLU MODIFIKASI */ -address_child alokasi(infotype_child x); -void dealokasi(address_child &P); -address_child findElm(List_child L, infotype_child x); -void printInfo(List_child L); +address_child alokasi_C(infotype_child x); +void dealokasi_C(address_child &P); +address_child findElm_C(List_child L, infotype_child x); +void printInfo_C(List_child L); #endif // LIST_CHILD_H_INCLUDED diff --git a/Multi_IIIB/list_parent.cpp b/Multi_IIIB/list_parent.cpp index 1d338c0..09e695c 100644 --- a/Multi_IIIB/list_parent.cpp +++ b/Multi_IIIB/list_parent.cpp @@ -1,62 +1,172 @@ #include "list_parent.h" -void createList(List_parent &L) { +void createList_P(List_parent &L) { /** * FS : first(L) diset Nil */ first(L) = NULL; } -address_parent alokasi(infotype_parent x) { +address_parent alokasi_P(infotype_parent x) { /** * FS : mengembalikan elemen list baru dengan info = x, next elemen = Nil */ address_parent P; + List_relasi LR; + createList_R(LR); P = new elmlist_parent; info(P) = x; next(P) = NULL; - createList(child(P)); + createList_R(child(P)); return P; } -void insertFirst(List_parent &L, address_parent P) { +void insertFirst_P(List_parent &L, address_parent P) { /** * IS : List_parent L mungkin kosong * FS : elemen yang ditunjuk P menjadi elemen pertama pada List_parent L * next dari last elemen menunjuk ke first elemen */ - address_parent Q; - if(first(L) == NULL) { - first(L) = P; - next(P) = P; - } else { - Q = first(L); - while(next(Q) != first(L)) { + if(first(L)==NULL){ + first(L)=P; + }else{ + next(P)=first(L); + first(L)=P; + } +} + +void insertLast_P(List_parent &L, address_parent P){ + address_parent Q = first(L); + if(first(L)!=NULL){ + while(Q!=NULL){ Q = next(Q); } - next(P) = first(L); - next(Q) = P; - first(L) = P; + next(Q)=P; + }else{ + first(L)=P; + } +} + +void insertAfter_P(List_parent &L, address_parent Prec, address_parent P){ + if(Prec != NULL){ + if(next(Prec)==NULL){ + insertLast_P(L,P); + }else{ + next(P)=next(Prec); + next(Prec)=P; + } + } +} + + +void deleteFirst_P(List_parent &L, address_parent &P){ + + if(first(L)!=NULL){ + if(next(first(L))==NULL){ + P = first(L); + first(L) = NULL; + }else{ + P = first(L); + first(L)= next(first(L)); + P = NULL; + } + }else{ + cout<<"List Kosong \n"; + } +} + +void deleteLast_P(List_parent &L, address_parent &P){ + if(first(L)!=NULL){ + if(next(first(L))==NULL){ + P = first(L); + first(L)=NULL; + }else{ + address_parent Q = first(L); + while(Q != NULL){ + Q = next(Q); + } + P = Q; + Q = NULL; + } + } +} + +void deleteAfter_P(List_parent &L, address_parent Prec, address_parent &P){ + if(Prec!=NULL){ + if(next(next(Prec))){ + deleteLast_P(L,P); + }else{ + P = next(Prec); + if(next(P)==NULL){ + P = NULL; + }else{ + next(Prec)=next(P); + P = NULL; + } + } } } +int countSong(address_parent P){ + int i = 0; + if(first(child(P)) == NULL){ + return 0; + }else{ + address_relasi Q = first(child(P)); + while(Q!=NULL){ + i++; + Q = next(Q); + } + } + return i; +} -void printInfo(List_parent L) { +void printInfo_P(List_parent L) { /** * FS : menampilkan info seluruh elemen list L */ address_parent P = first(L); if(first(L)!=NULL) { - do { - cout<info.id<info.name<info.genre<info.id != x.id){ + if(P->info.id == x.id){ + return P; + }else{ + P=next(P); + } + } + }else{ + return NULL; + } + //---------------------------------------- + return P; +} + + +/** ==========Ditambah========== */ + +address_parent findElmName_P(List_parent L, infotype_parent x) { /** * IS : List_parent L mungkin kosong * FS : mengembalikan elemen dengan info nim = x.nim, @@ -65,7 +175,7 @@ address_parent findElm(List_parent L, infotype_parent x) { */ address_parent P = first(L); do { - if(info(P) == x) { + if(P->info.name == x.name) { return P; } P = next(P); diff --git a/Multi_IIIB/list_parent.h b/Multi_IIIB/list_parent.h index c89fa6a..2cb74d7 100644 --- a/Multi_IIIB/list_parent.h +++ b/Multi_IIIB/list_parent.h @@ -11,35 +11,43 @@ using namespace std; #define info(P) P->info #define child(P) P->child -typedef int infotype_parent; +struct artist{ + int id; + string name; + string genre; +}; + +typedef artist infotype_parent; typedef struct elmlist_parent *address_parent; struct elmlist_parent { infotype_parent info; List_relasi child; address_parent next; + }; struct List_parent { address_parent first; }; - /** TIDAK PERLU MODIFIKASI */ -void createList(List_parent &L); -void insertFirst(List_parent &L, address_parent P); -void insertAfter(List_parent &L, address_parent Prec, address_parent P); -void insertLast(List_parent &L, address_parent P); -void deleteFirst(List_parent &L, address_parent &P); -void deleteLast(List_parent &L, address_parent &P); -void deleteAfter(List_parent &L, address_parent Prec, address_parent &P); +void createList_P(List_parent &L); +void insertFirst_P(List_parent &L, address_parent P); +void insertAfter_P(List_parent &L, address_parent Prec, address_parent P); +void insertLast_P(List_parent &L, address_parent P); +void deleteFirst_P(List_parent &L, address_parent &P); +void deleteLast_P(List_parent &L, address_parent &P); +void deleteAfter_P(List_parent &L, address_parent Prec, address_parent &P); +address_parent findElm_P(List_parent L, infotype_parent x); /** PERLU MODIFIKASI */ -address_parent alokasi(infotype_parent x); -void dealokasi(address_parent &P); -address_parent findElm(List_parent L, infotype_parent x); -void printInfo(List_parent L); +address_parent alokasi_P(infotype_parent x); +void dealokasi_P(address_parent &P); +address_parent findElm_P(List_parent L, infotype_parent x); +void printInfo_P(List_parent L); +address_parent findElmName_P(List_parent L, infotype_parent x); #endif // LIST_PARENT_H_INCLUDED diff --git a/Multi_IIIB/list_relasi.cpp b/Multi_IIIB/list_relasi.cpp index 9fe2c64..457b84e 100644 --- a/Multi_IIIB/list_relasi.cpp +++ b/Multi_IIIB/list_relasi.cpp @@ -1,42 +1,121 @@ #include "list_relasi.h" -void createList(List_relasi &L) { +void createList_R(List_relasi &L) { first(L) = NULL; } -address_relasi alokasi(address_child C) { +address_relasi alokasi_R(address_child C) { address_relasi P = new elmlist_relasi; info(P) = C; next(P) = NULL; return P; } -void insertFirst(List_relasi &L, address_relasi P) { - next(P) = first(L); - first(L) = P; +void insertFirst_R(List_relasi &L, address_relasi P) { + if(first(L)==NULL){ + first(L) = P; + }else{ + next(P) = first(L); + first(L) = P; + } +} + +void insertLast_R(List_relasi &L, address_relasi P){ + if(first(L)==NULL){ + first(L)=P; + }else{ + address_relasi Q = first(L); + while(Q!=NULL){ + Q = next(Q); + } + next(Q) = P; + + } + +} + +void insertAfter_R(List_relasi &L, address_relasi Prec, address_relasi P){ + if(Prec!=NULL){ + if(next(Prec)==NULL){ + insertLast_R(L,P); + }else{ + next(P)=next(Prec); + next(Prec)=P; + } + } +} + +void deleteFirst_R(List_relasi &L, address_relasi &P){ + if(next(first(L))==NULL){ + P = first(L); + first(L)=NULL; + }else{ + P = first(L); + first(L) = next(first(L)); + next(P) = NULL; + } +} + +void deleteLast_R(List_relasi &L, address_relasi &P){ + if(next(first(L))==NULL){ + deleteFirst_R(L,P); + }else{ + address_relasi Q //= first(L); + ; + while(next(Q)!=NULL){ + Q = next(Q); + } + P = next(Q); + next(Q)=NULL; + } +} + +void deleteAfter_R(List_relasi &L, address_relasi Prec, address_relasi &P){ + if(Prec!=NULL){ + if(next(Prec)==NULL){ + deleteLast_R(L,P); + }else{ + P = next(Prec); + next(Prec) = next(P); + next(P) = NULL; + } + } } -void printInfo(List_relasi L) { +void printInfo_R(List_relasi L) { address_relasi P = first(L); while(P !=NULL) { - cout<<"->"<info->info.name_song<info != C){ + if(P->info == C){ + return P; + }else{ + P=next(P); + } } - P = next(P); } - return NULL; + //---------------------------------------- + return P; + } +void dealokasi_R(address_relasi &P){ + delete P; +} + -void insertAfter(address_relasi &Prec, address_relasi P) { +void insertAfter_R(address_relasi &Prec, address_relasi P) { next(P) = next(Prec); next(Prec) = P; + } diff --git a/Multi_IIIB/list_relasi.h b/Multi_IIIB/list_relasi.h index bd8f2e8..225c09f 100644 --- a/Multi_IIIB/list_relasi.h +++ b/Multi_IIIB/list_relasi.h @@ -5,6 +5,7 @@ #include "list_child.h" #include + using namespace std; #define next(P) P->next @@ -23,20 +24,20 @@ struct List_relasi{ }; /** TIDAK PERLU MODIFIKASI */ -void createList(List_relasi &L); -void insertFirst(List_relasi &L, address_relasi P); -void insertLast(List_relasi &L, address_relasi P); -void insertAfter(address_relasi Prec, address_relasi P); -void deleteFirst(List_relasi &L, address_relasi &P); -void deleteLast(List_relasi &L, address_relasi &P); -void deleteAfter(address_relasi Prec, address_relasi &P); +void createList_R(List_relasi &L); +void insertFirst_R(List_relasi &L, address_relasi P); +void insertLast_R(List_relasi &L, address_relasi P); +void insertAfter_R(List_relasi &L, address_relasi Prec, address_relasi P); +void deleteFirst_R(List_relasi &L, address_relasi &P); +void deleteLast_R(List_relasi &L, address_relasi &P); +void deleteAfter_R(List_relasi &L, address_relasi Prec, address_relasi &P); /** PERLU MODIFIKASI */ -address_relasi alokasi( address_child C); -void dealokasi(address_relasi &P); -address_relasi findElm(List_relasi L, address_child C); -void printInfo(List_relasi L); +address_relasi alokasi_R( address_child C); +void dealokasi_R(address_relasi &P); +address_relasi findElm_R(List_relasi L, address_child C); +void printInfo_R(List_relasi L); #endif // LIST_RELASI_H_INCLUDED diff --git a/Multi_IIIB/main.cpp b/Multi_IIIB/main.cpp index 7169aa7..c4eda2f 100644 --- a/Multi_IIIB/main.cpp +++ b/Multi_IIIB/main.cpp @@ -1,86 +1,135 @@ #include +#include +#include +#include +#include using namespace std; + #include "list_child.h" #include "list_parent.h" +#include "operation.h" -int main() -{ - cout << "Bentuk IIIB - Contoh Relasi M-N" << endl; - - List_parent LP; +int main(){ List_child LC; - address_child C; - address_parent P; - address_relasi R; - - createList(LP); - createList(LC); - - /** insert parent */ - P = alokasi(3); - insertFirst(LP, P); - P = alokasi(7); - insertFirst(LP, P); - P = alokasi(2); - insertFirst(LP, P); - P = alokasi(4); - insertFirst(LP, P); - - cout<<"list parent"<>i; + switch(i){ + case 1:{ + system("cls"); + insertParent(LP); + getch(); + system("cls"); + goto menu; + } + case 2:{ + system("cls"); + insertChild(LC); + getch(); + system("cls"); + goto menu; + } + case 3:{ + system("cls"); + connectList(LP,LC); + getch(); + system("cls"); + goto menu; + } + case 4:{ + system("cls"); + deleteChild(LP,LC); + getch(); + system("cls"); + goto menu; + } + case 5:{ + system("cls"); + DisplayParent(LP); + getch(); + system("cls"); + goto menu; + } + case 6:{ + system("cls"); + displayChild(LC); + getch(); + system("cls"); + goto menu; + } + case 7:{ + system("cls"); + printALL(LP); + getch(); + system("cls"); + goto menu; + } + case 8:{ + system("cls"); + checkConnection(LP,LC); + getch(); + system("cls"); + goto menu; + } + case 9:{ + system("cls"); + disconnect(LP,LC); + getch(); + system("cls"); + goto menu; + } + case 10:{ + system("cls"); + PlayArtist(LP); + getch(); + system("cls"); + goto menu; + } + case 11:{ + system("cls"); + printChildOfParent(LP); + getch(); + system("cls"); + goto menu; + } + case 12:{ + system("cls"); + MusicById(LC); + getch(); + system("cls"); + goto menu; + } + default :{ + system("cls"); + goto menu; + } + } - return 0; } diff --git a/Multi_IIIB/obj/Debug/control.o b/Multi_IIIB/obj/Debug/control.o new file mode 100644 index 0000000..c52ff82 Binary files /dev/null and b/Multi_IIIB/obj/Debug/control.o differ diff --git a/Multi_IIIB/obj/Debug/list_child.o b/Multi_IIIB/obj/Debug/list_child.o index 54223be..0b98caf 100644 Binary files a/Multi_IIIB/obj/Debug/list_child.o and b/Multi_IIIB/obj/Debug/list_child.o differ diff --git a/Multi_IIIB/obj/Debug/list_parent.o b/Multi_IIIB/obj/Debug/list_parent.o index 1ed51f0..ca4905f 100644 Binary files a/Multi_IIIB/obj/Debug/list_parent.o and b/Multi_IIIB/obj/Debug/list_parent.o differ diff --git a/Multi_IIIB/obj/Debug/list_relasi.o b/Multi_IIIB/obj/Debug/list_relasi.o index 91fa316..95221c8 100644 Binary files a/Multi_IIIB/obj/Debug/list_relasi.o and b/Multi_IIIB/obj/Debug/list_relasi.o differ diff --git a/Multi_IIIB/obj/Debug/main.o b/Multi_IIIB/obj/Debug/main.o index d0f1ebd..736b49c 100644 Binary files a/Multi_IIIB/obj/Debug/main.o and b/Multi_IIIB/obj/Debug/main.o differ diff --git a/Multi_IIIB/obj/Debug/operation.o b/Multi_IIIB/obj/Debug/operation.o new file mode 100644 index 0000000..1644539 Binary files /dev/null and b/Multi_IIIB/obj/Debug/operation.o differ diff --git a/Multi_IIIB/operation.cpp b/Multi_IIIB/operation.cpp new file mode 100644 index 0000000..85076a0 --- /dev/null +++ b/Multi_IIIB/operation.cpp @@ -0,0 +1,241 @@ +#include "operation.h" + + +void insertParent(List_parent &L){ + address_parent P = NULL; + infotype_parent x; + cout<<"Input ID Artist : ";cin>>x.id; + P = findElm_P(L,x); + if(P==NULL){ + cout<<"Input Name Artist : ";cin>>x.name; + cout<<"input Genre Artis : ";cin>>x.genre; + P = alokasi_P(x); + insertFirst_P(L,P); + cout<<"Artist Inserted ! \n"; + }else{ + cout<<"Artist is already Exist \n"; + getch(); + system("cls"); + insertParent(L); + } +} + +void DisplayParent(List_parent &L){ + if(first(L)==NULL){ + cout<<"List is Empty \n"; + }else{ + printInfo_P(L); + } +} + +void insertChild(List_child &L){ + address_child P = NULL; + infotype_child x; + cout<<"Input ID Music : ";cin>>x.id_song; + P = findElm_C(L,x); + if(P==NULL){ + cout<<"Input Song Name : ";cin>>x.name_song; + x.name_loc = "asset/"+x.name_song+".wav"; + P = alokasi_C(x); + insertFirst_C(L,P); + }else{ + cout<<"Song is already exist ! "<>xp.id; + P = findElm_P(LP,xp); + if(P!=NULL){ + cout<<"input id Song : ";cin>>xc.id_song; + C = findElm_C(LC,xc); + if(C!=NULL){ + R = alokasi_R(C); + insertFirst_R(child(P),R); + cout<>x.id; + address_parent P = findElm_P(LP,x); + if(P!=NULL){ + cout<>xp.id; + P = findElm_P(LP,xp); + if(P!=NULL){ + cout<<"Input Id Song : ";cin>>xc.id_song; + C = findElm_C(LC,xc); + if(C!=NULL){ + R = findElm_R(child(P),C); + if(R==first(child(P))){ + deleteFirst_R(child(P),AR); + }else if(next(R)==NULL){ + deleteLast_R(child(P),AR); + }else{ + deleteAfter_R(child(P),R,AR); + } + cout< "; + R = first(child(Q)); + while(R!=NULL){ + cout<>x.id; + address_parent P = findElm_P(L,x); + if(P!=NULL){ + address_relasi Q = first(child(P)); + while(Q!=NULL){ + cout<>xc.id_song; + address_child Target = findElm_C(LC,xc); + if(Target!=NULL){ + while(P!=NULL){ + address_relasi R = first(child(P)); + while(R!=NULL){ + if(Target == R->info){ + if(R==first(child(P))){ + deleteFirst_R(child(P),AR); + }else if(next(R)==NULL){ + deleteLast_R(child(P),AR); + }else{ + address_relasi RT = first(child(P)); + while(next(RT)!= R){ + RT = next(RT); + } + deleteAfter_R(child(P),RT,AR); + } + if(AR!=NULL){ + dealokasi_R(AR); + } + } + R=next(R); + } + } + } + if(Target!=NULL){ + if(Target==first(LC)){ + deleteFirst_C(LC,AC); + }else if(Target == last(LC)){ + deleteLast_C(LC,AC); + }else{ + deleteAfter_C(LC,prev(Target),AC); + } + cout<info.name_loc; + cout<<"Playing "<>x.id; + P = findElm_P(LP,x); + if(P!=NULL){ + address_relasi R = first(child(P)); + while(R!=NULL){ + //cout<info<info); + R=next(R); + } + }else{ + cout<<"id not found ! \n"; + } +} + +void MusicById(List_child LC){ + infotype_child x; + address_child P; + cout<<"Input Artist ID : ";cin>>x.id_song; + P = findElm_C(LC,x); + if(P!=NULL){ + MusicPlayer(P); + }else{ + cout<<"music not found \n"; + } +} + + diff --git a/Multi_IIIB/operation.h b/Multi_IIIB/operation.h new file mode 100644 index 0000000..1ed63fe --- /dev/null +++ b/Multi_IIIB/operation.h @@ -0,0 +1,25 @@ +#include "list_child.h" +#include "list_parent.h" +#include "list_relasi.h" +#include +#include +#include +#include +#include + +using namespace std; + +void insertParent(List_parent &L); +void DisplayParent(List_parent &L); +void insertChild(List_child &L); +void displayChild(List_child &L); +void connectList(List_parent LP, List_child LC); +void checkConnection(List_parent LP, List_child LC); +void disconnect(List_parent &LP, List_child LC); +void printALL(List_parent L); +void printChildOfParent(List_parent L); +void deleteChild(List_parent &LP, List_child &LC); +void deleteParent(List_parent &L); +void MusicPlayer(address_child C); +void PlayArtist(List_parent LP); +void MusicById(List_child LC);