diff --git a/Multi_III/Multi_III.depend b/Multi_III/Multi_III.depend index e6cce59..1dccddd 100644 --- a/Multi_III/Multi_III.depend +++ b/Multi_III/Multi_III.depend @@ -51,3 +51,39 @@ "list_parent.h" +1524922551 source:c:\users\c3x\documents\github\asd_multilist\multi_iii\list_child.cpp + "list_child.h" + +1524919451 c:\users\c3x\documents\github\asd_multilist\multi_iii\list_child.h + + + + + +1524919962 source:c:\users\c3x\documents\github\asd_multilist\multi_iii\list_parent.cpp + "list_parent.h" + +1524912378 c:\users\c3x\documents\github\asd_multilist\multi_iii\list_parent.h + + + + + +1524925417 source:c:\users\c3x\documents\github\asd_multilist\multi_iii\list_relasi.cpp + "list_relasi.h" + +1524924073 c:\users\c3x\documents\github\asd_multilist\multi_iii\list_relasi.h + "list_relasi.h" + "list_child.h" + "list_parent.h" + + + + + +1524925417 source:c:\users\c3x\documents\github\asd_multilist\multi_iii\main.cpp + + "list_child.h" + "list_parent.h" + "list_relasi.h" + diff --git a/Multi_III/Multi_III.layout b/Multi_III/Multi_III.layout index 8a208ed..7638b2a 100644 --- a/Multi_III/Multi_III.layout +++ b/Multi_III/Multi_III.layout @@ -2,39 +2,39 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/Multi_III/bin/Debug/Multi_III.exe b/Multi_III/bin/Debug/Multi_III.exe index 7692f3e..79f021c 100644 Binary files a/Multi_III/bin/Debug/Multi_III.exe and b/Multi_III/bin/Debug/Multi_III.exe differ diff --git a/Multi_III/list_child.cpp b/Multi_III/list_child.cpp index 33d09f9..308fbb0 100644 --- a/Multi_III/list_child.cpp +++ b/Multi_III/list_child.cpp @@ -13,40 +13,135 @@ address_child alokasi(infotype_child x) { return P; } +void dealokasi(address_child &P) { + /** + * FS : delete element pointed by P + */ + delete(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; + 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) { - address_child P = first(L); - while(P !=NULL) { - cout<<"->"<info.id<info.name<info.id == x.id){ + return P; + }else{ + P = next(P); + } + }while(next(P)!=first(L) && P->info.id != x.id); + + }else{ + return NULL; + } + if(P->info.id!=x.id){ + return NULL; + } + return P; } diff --git a/Multi_III/list_child.h b/Multi_III/list_child.h index e11826c..70abf37 100644 --- a/Multi_III/list_child.h +++ b/Multi_III/list_child.h @@ -1,8 +1,10 @@ #ifndef LIST_CHILD_H_INCLUDED #define LIST_CHILD_H_INCLUDED - -#include +#include +#include +#include +#include using namespace std; #define next(P) P->next @@ -11,7 +13,12 @@ using namespace std; #define last(L) L.last #define info(P) P->info -typedef string infotype_child; +struct memb{ + int id; + string name; +}; + +typedef memb infotype_child; typedef struct elmlist_child *address_child; struct elmlist_child{ diff --git a/Multi_III/list_parent.cpp b/Multi_III/list_parent.cpp index bb71ae3..6856543 100644 --- a/Multi_III/list_parent.cpp +++ b/Multi_III/list_parent.cpp @@ -19,27 +19,103 @@ address_parent alokasi(infotype_parent x) { return P; } +void dealokasi(address_parent &P) { + /** + * FS : delete element pointed by P + */ + delete(P); +} + void insertFirst(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 + * FS : element pointed by P became the first element in List L */ - address_parent Q; - if(first(L) == NULL) { - first(L) = P; - next(P) = P; - } else { - Q = first(L); - while(next(Q) != first(L)) { - Q = next(Q); + if (first(L)==NULL){ + first(L)=P; + }else{ + next(P)= first(L); + first(L)=P; + } +} + +void insertLast(List_parent &L, address_parent P) { + /** + * FS : element pointed by P became the last element in List L + */ + address_parent(Q)=first(L); + if (first(L)==NULL){ + first(L)=P; + }else{ + while (next(Q)!= NULL) { + Q=next(Q); } - next(P) = first(L); - next(Q) = P; - first(L) = P; + next(Q)=P; } } +void insertAfter_P(List_parent &L, address_parent Prec, address_parent P){ + if(Prec != NULL){ + if(next(Prec)==NULL){ + insertLast(L,P); + }else{ + next(P)=next(Prec); + next(Prec)=P; + } + } +} + +void deleteFirst(List_parent &L, address_parent &P) { + /** + * FS : first element in List L is removed and is pointed by P + */ + if (first(L)==NULL){} + else{ + P=first(L); + first(L) = next(first(L)); + next(P)=NULL; + } +} + +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{} +} + +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(address_parent Prec, address_parent &P) { + /** + * is removed and pointed by pointer P + */ + if (Prec!=NULL){ + P=next(Prec); + next(Prec)=next(next(Prec)); + next(P)=NULL; + } +} void printInfo(List_parent L) { /** @@ -47,10 +123,13 @@ void printInfo(List_parent L) { */ address_parent P = first(L); if(first(L)!=NULL) { - do { - cout<info.idb<info.name<info.genre<info.idb!=x.idb){ + if(P->info.idb==x.idb){ + return P; + } else{ + P=next(P); + } } - P = next(P); - } while(P != first(L)); - return NULL; + } + return P; } diff --git a/Multi_III/list_parent.h b/Multi_III/list_parent.h index ae3d24b..4deb3f5 100644 --- a/Multi_III/list_parent.h +++ b/Multi_III/list_parent.h @@ -1,14 +1,23 @@ #ifndef LIST_PARENT_H_INCLUDED #define LIST_PARENT_H_INCLUDED -#include +#include +#include +#include +#include using namespace std; #define first(L) L.first #define next(P) P->next #define info(P) P->info -typedef int infotype_parent; +struct book{ + int idb; + string name; + string genre; +}; + +typedef book infotype_parent; typedef struct elmlist_parent *address_parent; struct elmlist_parent { diff --git a/Multi_III/list_relasi.cpp b/Multi_III/list_relasi.cpp index f498388..66e7b04 100644 --- a/Multi_III/list_relasi.cpp +++ b/Multi_III/list_relasi.cpp @@ -13,18 +13,88 @@ address_relasi alokasi(address_parent P, address_child C) { } void insertFirst(List_relasi &L, address_relasi P) { - next(P) = first(L); - first(L) = P; + if(first(L)==NULL){ + first(L)=P; + }else{ + next(P)=first(L); + first(L)=P; + } +} + +void insertLast(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(List_relasi &L, address_relasi Prec, address_relasi P){ + if(Prec != NULL){ + if(next(Prec)==NULL){ + insertLast(L,P); + }else{ + next(P)=next(Prec); + next(Prec)=P; + } + } } void printInfo(List_relasi L) { address_relasi P = first(L); while(P !=NULL) { - cout<"<child->info.name<<" <-> "<parent->info.name<>xp.idb; + P = findElm(LP,xp); + if(P!=NULL){ + cout<<"input id Member : ";cin>>xc.id; + C = findElm(LC,xc); + if(C!=NULL){ + R = alokasi(P,C); + insertFirst(LR,R); + cout< +#include +#include +#include +#include using namespace std; #define next(P) P->next @@ -40,6 +43,7 @@ address_relasi alokasi( address_parent P, address_child C); void dealokasi(address_relasi &P); address_relasi findElm(List_relasi L, address_parent P, address_child C); void printInfo(List_relasi L); +void connectList(List_relasi &LR, List_parent LP, List_child LC); #endif // LIST_RELASI_H_INCLUDED diff --git a/Multi_III/main.cpp b/Multi_III/main.cpp index c65e9a6..a4b1197 100644 --- a/Multi_III/main.cpp +++ b/Multi_III/main.cpp @@ -7,90 +7,139 @@ using namespace std; int main() { - cout << "Bentuk III - Contoh Relasi M-N" << endl; - - List_parent LP; List_child LC; + List_parent LP; List_relasi LR; - address_child C; - address_parent P; - address_relasi R; - createList(LP); + int i; + + infotype_child xc; + infotype_parent xp; + createList(LC); + createList(LP); createList(LR); - /** 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"); + cout<<"<====Input Book=====> \n"; + cout<<"===================== \n"; + address_parent P = NULL; + cout<<"Input Book ID : ";cin>>xp.idb; + P = findElm(LP,xp); + if(P==NULL){ + cout<<"Input Book Name : ";cin>>xp.name; + cout<<"input Book Genre : ";cin>>xp.genre; + P = alokasi(xp); + insertLast(LP,P); + cout<<"Done! \n"; + }else{ + cout<<"Book ID is already exist!"; + } + getch(); + system("cls"); + goto menu; + } + + case 2:{ + system("cls"); + cout<<"<====Input Member===> \n"; + cout<<"===================== \n"; + address_child Q = NULL; + cout<<"Input Member ID : ";cin>>xc.id; + Q = findElm(LC,xc); + if(Q==NULL){ + cout<<"Input Member Name : ";cin>>xc.name; + Q = alokasi(xc); + insertFirst(LC,Q); + cout<<"Done! \n"; + }else{ + cout<<"Member ID is already exist!"; + } + getch(); + system("cls"); + goto menu; + } + + case 3:{ + system("cls"); + connectList(LR,LP,LC); + getch(); + system("cls"); + goto menu; + + } + + case 4:{ + + } + + case 5:{ + + } + + case 6:{ + + } + + case 7:{ + system("cls"); + cout<<"<=====Book List=====> \n"; + cout<<"===================== \n"; + cout< \n"; + cout<<"======================= \n"; + cout< \n"; + cout<<"======================= \n"; + cout<