From 6a6e96c153fc0a84c235dbcb6331caf38521c3de Mon Sep 17 00:00:00 2001 From: DaffaBarin Date: Fri, 21 Feb 2020 14:52:05 +0700 Subject: [PATCH 1/7] Update list.cpp --- list.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 13 deletions(-) diff --git a/list.cpp b/list.cpp index fe0655c..96765df 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,7 +20,14 @@ 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; + //---------------------------------------- @@ -31,7 +39,7 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - your code here + delete P; //---------------------------------------- @@ -43,7 +51,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) { + next(P) = first(L); + prev(first(L)) = P; + first(L) = P; + } else { + first(L) = P; + last(L) = P; + } //---------------------------------------- @@ -55,7 +70,10 @@ void insertLast(List &L, address P) { * FS : element pointed by P became the last element in List L */ //-------------your code here------------- - your code here + next(last(L)) = P; + prev(P) = last(L); + last(L) = P; + //---------------------------------------- @@ -70,8 +88,10 @@ address findElm(List L, infotype x) { address P; //-------------your code here------------- - your code here - + P = first(L); + while (P != NULL && info(P).ID != x.ID) { + P = next(P); + } //---------------------------------------- return P; @@ -83,8 +103,16 @@ 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 - + if (first(L) == last(L)) { + P = first(L); + first(L) = NULL; + last(L) = NULL; + } else if (first(L) != NULL) { + P = first(L); + first(L) = next(P); + next(P) = NULL; + prev(first(L)) = NULL; + } //---------------------------------------- @@ -96,7 +124,16 @@ 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 + if (last(L) != NULL) { + P = last(L); + last(L) = prev(P); + prev(P) = NULL; + next(last(L)) = NULL; + } else if (first(L) == last(L)) { + P = first(L); + first(L) = NULL; + last(L) = NULL; + } @@ -109,7 +146,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 << endl; //---------------------------------------- @@ -123,7 +165,16 @@ void insertAfter(List &L, address Prec, address P) { * pointed by pointer Prec */ //-------------your code here------------- - your code here + if (first(L) == NULL) { + insertFirst(L, P); + } else if (first(L) != last(L) && Prec != NULL) { + next(P) = next(Prec); + P -> prev = Prec; + prev(next(Prec)) = P; + next(Prec) = P; + } else if (Prec != NULL) { + insertLast(L, P); + } //---------------------------------------- @@ -135,7 +186,17 @@ void deleteAfter(List &L, address Prec, address &P) { * is removed and pointed by pointer P */ //-------------your code here------------- - your code here + if (first(L) == last(L) && Prec != NULL) { + deleteFirst(L, P); + } else if (next(Prec) != last(L) && Prec != NULL) { + P = next(Prec); + next(Prec) = next(P); + prev(next(P)) = Prec; + next(P) = NULL; + prev(P) = NULL; + } else if (Prec != NULL) { + deleteLast(L, P); + } //---------------------------------------- From 3c7356f46bf8feb4d603a4f3d01ba10a7c4ad67a Mon Sep 17 00:00:00 2001 From: DaffaBarin Date: Fri, 21 Feb 2020 14:53:07 +0700 Subject: [PATCH 2/7] Update list.h --- list.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/list.h b/list.h index c21344f..f5a97f7 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,13 +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; //---------------------------------------- }; From a886d9794a9c378cc7e80cda9d729f91d3b145cb Mon Sep 17 00:00:00 2001 From: DaffaBarin Date: Fri, 21 Feb 2020 14:53:36 +0700 Subject: [PATCH 3/7] Update main.cpp --- main.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 9e0b483..a6c7553 100644 --- a/main.cpp +++ b/main.cpp @@ -51,7 +51,45 @@ void mainMenu() { case 1: X = create_data(); P = allocate(X); - insertFirst(L,P) + insertFirst(L,P); + break; + case 2: + printInfo(L); + break; + case 3: + cout << "Masukkan ID yang ingin dicari : "; + cin >> X.ID; + P = findElm(L, X); + if (P != NULL) { + view_data(info(P)); + } else { + cout << "DATA TIDAK DITEMUKAN!\n"; + } + break; + case 4: + cout << "Masukkan ID yang ingin diedit : "; + cin >> X.ID; + P = findElm(L, X); + if (P != NULL) { + edit_data(info(P)); + } else { + cout << "DATA TIDAK DITEMUKAN!\n"; + } + break; + case 5: + cout << "Masukkan ID yang ingin didelete : "; + cin >> X.ID; + if (findElm(L, X) != NULL) { + deletebyID(L, X.ID); + } else { + cout << "DATA TIDAK DITEMUKAN" << endl; + } + break; + case 6: + savePassedMember(L, L_passed); + break; + case 7: + printInfo(L_passed); break; } } while(true); From bed738c347d22ea7c25ec8a657e6b306525974d1 Mon Sep 17 00:00:00 2001 From: DaffaBarin Date: Fri, 21 Feb 2020 14:54:46 +0700 Subject: [PATCH 4/7] Update my_data.cpp --- my_data.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/my_data.cpp b/my_data.cpp index 68b9d77..aba192b 100644 --- a/my_data.cpp +++ b/my_data.cpp @@ -1,4 +1,4 @@ - + #include "my_data.h" /** @@ -15,8 +15,14 @@ mytype create_data() { mytype d; // =========================== // YOUR CODE HERE - your code here - + cout << "Masukkan ID : "; + cin >> d.ID; + cout << "Masukkan Nama : "; + cin >> d.name; + cout << "Masukkan ranking : "; + cin >> d.rank; + cout << "Masukkan score : "; + cin >> d.score; @@ -32,7 +38,7 @@ void view_data(mytype d) { // =========================== // YOUR CODE HERE - your code here + cout << d.ID << " - " << d.name << " - "<< d.rank << " - " << d.score << endl; @@ -50,7 +56,12 @@ void edit_data(mytype &d) { // =========================== // YOUR CODE HERE - your code here + cout << "Masukkan pergantian nama : "; + cin >> d.name; + cout << "Masukkan pergantian rank : "; + cin >> d.rank; + cout << "Masukkan pergantian score : "; + cin >> d.score; From a38d392a2cbe73830a578e7eabbd9d6978ccba1a Mon Sep 17 00:00:00 2001 From: DaffaBarin Date: Fri, 21 Feb 2020 14:55:12 +0700 Subject: [PATCH 5/7] Update my_data.h --- my_data.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/my_data.h b/my_data.h index 2937b48..5aeb962 100644 --- a/my_data.h +++ b/my_data.h @@ -20,7 +20,10 @@ struct mytype { */ //================================================= // YOUR CODE STARTS HERE - your code here + int ID; + string name; + int rank; + float score; // YOUR CODE ENDS HERE //================================================= @@ -29,6 +32,6 @@ struct mytype { mytype create_data(); void view_data(mytype d); -void edit_data(mytype &d); +void edit_data(mytype &d); #endif // MY_DATA_H_INCLUDED From 30f6b0d884af644a292db67cd52ae86c0c36809c Mon Sep 17 00:00:00 2001 From: DaffaBarin Date: Fri, 21 Feb 2020 14:55:54 +0700 Subject: [PATCH 6/7] Update my_data.cpp --- my_data.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/my_data.cpp b/my_data.cpp index aba192b..8fbe5fa 100644 --- a/my_data.cpp +++ b/my_data.cpp @@ -2,9 +2,9 @@ #include "my_data.h" /** - CLASS : - NAME : - STUDENT ID : + CLASS : IF-43-05 + NAME : DAFFA BARIN TIZARD RIYADI + STUDENT ID : 1301190369 **/ mytype create_data() { From fe8b544cedbca6a953d15f59f1b60eae585680aa Mon Sep 17 00:00:00 2001 From: DaffaBarin Date: Fri, 21 Feb 2020 14:56:35 +0700 Subject: [PATCH 7/7] Update operation.cpp --- operation.cpp | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/operation.cpp b/operation.cpp index c2dc0b0..e8b145b 100644 --- a/operation.cpp +++ b/operation.cpp @@ -1,7 +1,7 @@ #include "list.h" #include "operation.h" #include "my_data.h" - + void insertAndSort(List &L, infotype x) { /** @@ -14,7 +14,17 @@ void insertAndSort(List &L, infotype x) { */ //-------------your code here------------- - your code here + address p, p1; + p = first(L); + if (p == NULL || info(p).ID > x.ID) { + insertFirst(L, allocate(x)); + } else if (findElm(L, x) == NULL) { + while (p != NULL && info(p).ID < x.ID) { + p1 = p; + p = next(p); + } + insertAfter(L, p1, allocate(x)); + } //---------------------------------------- @@ -29,7 +39,17 @@ void deletebyID(List &L, int id_x) { address Prec, P; //-------------your code here------------- - your code here + P = first(L); + if (P == first(L) && id_x == info(P).ID) { + deleteFirst(L, P); + } else { + while (P != NULL) { + if (id_x == info(P).ID && first(L) != last(L)) { + deleteAfter(L, prev(P), P); + } + P = next(P); + } + } //---------------------------------------- @@ -43,7 +63,22 @@ void savePassedMember(List &L, List &L2){ */ address P; //-------------your code here------------- - your code here + P = first(L); + address Q = P; + while (Q != NULL) { + P = Q; + if (info(P).score > 80) { + insertAndSort(L2, info(P)); + Q = next(Q); + if (prev(P) == NULL) { + deleteFirst(L, P); + } else { + deleteAfter(L, prev(P), P); + } + } else { + Q = next(Q); + } + } //----------------------------------------