diff --git a/ASD_Task_3.depend b/ASD_Task_3.depend index 831bfcc..027b8fc 100644 --- a/ASD_Task_3.depend +++ b/ASD_Task_3.depend @@ -52,3 +52,31 @@ "operation.h" "my_data.h" +1582384994 source:c:\users\asus\documents\github\asd_task_3\my_data.cpp + "my_data.h" + +1582291814 c:\users\asus\documents\github\asd_task_3\my_data.h + + +1582385561 source:c:\users\asus\documents\github\asd_task_3\main.cpp + + "list.h" + "operation.h" + "my_data.h" + +1582291814 c:\users\asus\documents\github\asd_task_3\list.h + + "my_data.h" + +1582044167 c:\users\asus\documents\github\asd_task_3\operation.h + "list.h" + +1582385746 source:c:\users\asus\documents\github\asd_task_3\operation.cpp + "list.h" + "operation.h" + "my_data.h" + +1582383117 source:c:\users\asus\documents\github\asd_task_3\list.cpp + "list.h" + "my_data.h" + diff --git a/ASD_Task_3.layout b/ASD_Task_3.layout index 17b1801..6ab5d73 100644 --- a/ASD_Task_3.layout +++ b/ASD_Task_3.layout @@ -2,39 +2,39 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/bin/Debug/ASD_Task_3.exe b/bin/Debug/ASD_Task_3.exe new file mode 100644 index 0000000..b854589 Binary files /dev/null and b/bin/Debug/ASD_Task_3.exe differ diff --git a/list.cpp b/list.cpp index fe0655c..ea71bd6 100644 --- a/list.cpp +++ b/list.cpp @@ -6,7 +6,8 @@ void createList(List &L) { * FS : set first(L) and last(L) with Null */ //-------------your code here------------- - your code here + first(L)=NULL; + last(L)=NULL; //---------------------------------------- @@ -19,11 +20,12 @@ address allocate(infotype x) { address P; //-------------your code here------------- - your code here - - - //---------------------------------------- + P = new elmlist; + info(P)=x; + next(P)=NULL; return P; + //---------------------------------------- + } void deallocate(address &P) { @@ -31,7 +33,7 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - your code here + delete P; //---------------------------------------- @@ -43,7 +45,14 @@ void insertFirst(List &L, address P) { * FS : element pointed by P became the first element in List L */ //-------------your code here------------- - your code here + if (first(L)==NULL && last(L)==NULL){ + first(L)=P; + last(L)=P; + }else{ + next(P)=first(L); + prev(first(L))=P; + first(L)=P; + } //---------------------------------------- @@ -55,7 +64,14 @@ void insertLast(List &L, address P) { * FS : element pointed by P became the last element in List L */ //-------------your code here------------- - your code here + if (first(L)==NULL && last(L)==NULL){ + first(L)=P; + last(L)=P; + }else{ + prev(P)=last(L); + next(last(L))=P; + last(L)=P; + } //---------------------------------------- @@ -68,12 +84,10 @@ address findElm(List L, infotype x) { return Null if such ID is not found */ - address P; - //-------------your code here------------- - your code here - - - //---------------------------------------- + address P=first(L); + while (P!=NULL && info(P).ID!=x.ID){ + P=next(P); + } return P; } @@ -83,7 +97,15 @@ void deleteFirst(List &L, address &P) { * FS : first element in List L is removed and is pointed by P */ //-------------your code here------------- - your code here + P=first(L); + if (first(L)==last(L)){ + first(L)=NULL; + last(L)=NULL; + }else { + first(L)=next(P); + next(P)=NULL; + prev(P)=NULL; + } @@ -96,7 +118,15 @@ void deleteLast(List &L, address &P) { * FS : last element in List L is removed and is pointed by P */ //-------------your code here------------- - your code here + P=last(L); + if (first(L)==last(L)){ + first(L)=NULL; + last(L)=NULL; + }else { + last(L)=prev(P); + prev(P)=NULL; + next(P)=NULL; + } @@ -109,8 +139,12 @@ void printInfo(List L) { * call the view_data function from my_data.h to print the info */ //-------------your code here------------- - your code here - + address P=first(L); + while(P!=NULL){ + view_data(info(P)); + P=next(P); + } + cout< * -* Type List : < -* first : address -* last : address +* Type List : < +* first : address +* last : address * > * **/ @@ -36,16 +36,14 @@ typedef mytype infotype; typedef struct elmlist *address; struct elmlist{ - //------------- your code here ----------- - - //---------------------------------------- + infotype info; + address next; + address prev; }; struct List{ - //------------- your code here ----------- - - - //---------------------------------------- + address first; + address last; }; diff --git a/main.cpp b/main.cpp index 9e0b483..1740f3f 100644 --- a/main.cpp +++ b/main.cpp @@ -51,7 +51,50 @@ void mainMenu() { case 1: X = create_data(); P = allocate(X); - insertFirst(L,P) + insertFirst(L,P); + break; + case 2: + printInfo(L); + cout<>X.ID; + P=findElm(L, X); + if (P!=NULL){ + view_data(info(P)); + }else{ + cout<<"Data Not Found"; + } + break; + case 4: + cout<<"Masukkan ID yang akan diedit: "; + cin>>X.ID; + P=findElm(L, X); + if (P!=NULL){ + edit_data(info(P)); + }else{ + cout<<"Data tidak ada"<>X.ID; + P=findElm(L, X); + if (P!=NULL){ + deletebyID(L, X.ID); + cout<<"Data telah dihapus"<>d.ID; + cout<<"Masukkan Nama: "; + cin>>d.name; + cout<<"Masukkan Rank: "; + cin>>d.Rank; + cout<<"Masukkan Score: "; + cin>>d.score; + cout<>d.name; + cout<<"Masukkan ranking baru: "; + cin>>d.Rank; + cout<<"Masukkan score baru: "; + cin>>d.score; + cout< x.ID){ + insertFirst(L, Q); + }else { + address P = first(L); + while(next(P)!=NULL && info(next(P)).ID<=x.ID){ + P=next(P); + } + if (info(P).ID==x.ID){ + cout<<"ID tidak boleh sama"; + }else if(next(Q)==NULL){ + insertLast(L, Q); + }else if (info(Q).ID!=x.ID){ + insertAfter(L, P, Q); + } + } //---------------------------------------- @@ -29,9 +45,20 @@ void deletebyID(List &L, int id_x) { address Prec, P; //-------------your code here------------- - your code here - - + if (first(L)!=NULL){ + if (info(first(L)).ID==id_x){ + deleteFirst(L, P); + }else if (info(last(L)).ID==id_x){ + deleteLast(L, P); + }else{ + address Q=first(L); + while (next(Q)!=NULL && info(next(Q)).ID != id_x){ + Q=next(Q); + } + Prec=Q; + deleteAfter(L, Prec, P); + } + } //---------------------------------------- } @@ -41,9 +68,16 @@ void savePassedMember(List &L, List &L2){ * IS : List L and L2 may be empty * FS : any element with score greater than 80 is moved to L2 */ - address P; + address P=first(L); + address Q; //-------------your code here------------- - your code here + while(P!=NULL){ + if (info(P).score>80){ + Q=allocate(info(P)); + insertLast(L2, Q); + } + P=next(P); + } //----------------------------------------