diff --git a/ASD_Task_3.depend b/ASD_Task_3.depend index 831bfcc..5a1cc85 100644 --- a/ASD_Task_3.depend +++ b/ASD_Task_3.depend @@ -52,3 +52,32 @@ "operation.h" "my_data.h" +1582346390 source:d:\kuliah\semester 2\asd_task_3\list.cpp + "list.h" + "my_data.h" + + +1582345192 d:\kuliah\semester 2\asd_task_3\list.h + + "my_data.h" + +1581926406 d:\kuliah\semester 2\asd_task_3\my_data.h + + +1582347753 source:d:\kuliah\semester 2\asd_task_3\main.cpp + + "list.h" + "operation.h" + "my_data.h" + +1581918600 d:\kuliah\semester 2\asd_task_3\operation.h + "list.h" + +1582383090 source:d:\kuliah\semester 2\asd_task_3\my_data.cpp + "my_data.h" + +1582382247 source:d:\kuliah\semester 2\asd_task_3\operation.cpp + "list.h" + "operation.h" + "my_data.h" + diff --git a/ASD_Task_3.layout b/ASD_Task_3.layout index 17b1801..ea29f5c 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..03123ae Binary files /dev/null and b/bin/Debug/ASD_Task_3.exe differ diff --git a/list.cpp b/list.cpp index fe0655c..cb161e5 100644 --- a/list.cpp +++ b/list.cpp @@ -1,14 +1,15 @@ #include "list.h" #include "my_data.h" +#include +using namespace std; void createList(List &L) { /** * FS : set first(L) and last(L) with Null */ //-------------your code here------------- - your code here - - + L.first = NULL; + L.last = NULL; //---------------------------------------- } @@ -19,9 +20,13 @@ address allocate(infotype x) { address P; //-------------your code here------------- - your code here - - + P = new elmlist; + info(P).ID = x.ID; + info(P).name = x.name; + info(P).rank = x.rank; + info(P).score = x.score; + next(P) = NULL; + prev(P) = NULL; //---------------------------------------- return P; } @@ -31,9 +36,7 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - your code here - - + delete P; //---------------------------------------- } @@ -43,9 +46,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 (L.first != NULL){ + P->next = L.first; + prev(L.first) = P; + L.first = P; + }else{ + L.first = P; + L.last = P; + } //---------------------------------------- } @@ -55,9 +63,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 (L.first!=NULL){ + P->prev = L.last; + next(L.last) = P; + L.last = P; + }else{ + L.last = P; + L.first = P; + } //---------------------------------------- } @@ -70,9 +83,15 @@ address findElm(List L, infotype x) { address P; //-------------your code here------------- - your code here - - + P = L.first; + if (L.first!=NULL){ + while (P != NULL && info(P).ID != x.ID) + { + P = P -> next; + } + }else{ + P=NULL; + } //---------------------------------------- return P; } @@ -83,10 +102,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 = L.first; + if (L.first!=last(L)){ + L.first = next(P); + next(P) = NULL; + prev(L.first)=NULL; + }else { + L.first = NULL; + L.last = NULL; + } //---------------------------------------- } @@ -96,10 +120,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 = L.last; + if (L.last!=first(L)){ + L.last = prev(P); + prev(P) = NULL; + next(L.last)=NULL; + }else { + L.first = NULL; + L.last = NULL; + } //---------------------------------------- } @@ -109,9 +138,16 @@ 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); + if (P==NULL){ + cout<<"Data Tidak Ada.."<next = Prec->next; + P->prev = Prec; + prev(next(Prec)) = P; + Prec->next = P; //---------------------------------------- } @@ -135,9 +173,11 @@ void deleteAfter(List &L, address Prec, address &P) { * is removed and pointed by pointer P */ //-------------your code here------------- - your code here - - + P = next(Prec); + next(Prec) = next(P); + prev(next(P)) = Prec; + next(P) = NULL; + prev(P) = NULL; //---------------------------------------- } diff --git a/list.h b/list.h index c21344f..c070520 100644 --- a/list.h +++ b/list.h @@ -23,9 +23,9 @@ using namespace std; * prev : address * > * -* Type List : < -* first : address -* last : address +* Type List : < +* first : address +* last : address * > * **/ @@ -37,14 +37,16 @@ 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..98bcbac 100644 --- a/main.cpp +++ b/main.cpp @@ -19,8 +19,9 @@ int main() { } void mainMenu() { - address P; + address P,R; infotype X; + mytype idpeserta; /** * IS : List has been created * PR : prints menu to user @@ -50,8 +51,63 @@ void mainMenu() { switch(choice) { case 1: X = create_data(); - P = allocate(X); - insertFirst(L,P) + insertAndSort(L,X); + cout<>idpeserta.ID; + P= findElm(L, idpeserta); + if(P!=NULL){ + view_data(info(P)); + }else{ + cout << "ID yang anda cari TIDAK ADA.." << endl; + } + cout<> idpeserta.ID; + P = findElm(L, idpeserta); + if (P!=NULL){ + cout<<"Silahkan mengedit data member: "<> idpeserta.ID; + P = findElm(L, idpeserta); + if (P!=NULL){ + deletebyID(L, idpeserta.ID); + cout<<"Data berhasil dihapus.."<>d.ID; + cout<<"Nama: "; + cin>>d.name; + cout<<"Rank: "; + cin>>d.rank; + cout<<"Score: "; + cin>>d.score; // =========================== return d; } @@ -32,11 +38,10 @@ void view_data(mytype d) { // =========================== // YOUR CODE HERE - your code here - - - - + cout<<"ID member: "<>d.name; + cout<>d.rank; + cout<>d.score; + cout<info.ID >= x.ID) { + insertFirst(L, allocate(x)); + } else if (info(last(L)).ID<=x.ID) { + insertLast(L, allocate(x)); + } else { + while (P != NULL && P->info.ID < x.ID) + { + P = P->next; + } + P = prev(P); + insertAfter(L, P, allocate(x)); + } //---------------------------------------- } @@ -27,10 +38,36 @@ void deletebyID(List &L, int id_x) { * FS : an element with ID info = id_x is deleted from List L (deallocate) */ - address Prec, P; + //address Prec, P; //-------------your code here------------- - your code here + address P,R; + P = L.first; + if (L.first==NULL){ + deleteFirst(L,R); + deallocate(R); + }else{ + if (P->info.ID == id_x) + { + deleteFirst(L, R); + deallocate(R); + } + else if (info(last(L)).ID == id_x) + { + deleteLast(L, R); + deallocate(R); + } + else + { + while (P != NULL && P->info.ID != id_x) + { + P = P->next; + } + P = prev(P); + deleteAfter(L, P, R); + deallocate(R); + } + } //---------------------------------------- } @@ -43,8 +80,13 @@ void savePassedMember(List &L, List &L2){ */ address P; //-------------your code here------------- - your code here - + P = L.first; + while(P!=NULL){ + if (info(P).score>=80){ + insertLast(L2, allocate(info(P))); + } + P = next(P); + } //---------------------------------------- }