diff --git a/ASD_Task_3.depend b/ASD_Task_3.depend index 831bfcc..30bbc2c 100644 --- a/ASD_Task_3.depend +++ b/ASD_Task_3.depend @@ -52,3 +52,17 @@ "operation.h" "my_data.h" +1582465119 source:c:\users\dell\documents\github\asd_task_3\list.cpp + "list.h" + "my_data.h" + +1582465119 c:\users\dell\documents\github\asd_task_3\list.h + + "my_data.h" + +1582465119 c:\users\dell\documents\github\asd_task_3\my_data.h + + +1582465119 source:c:\users\dell\documents\github\asd_task_3\my_data.cpp + "my_data.h" + diff --git a/ASD_Task_3.layout b/ASD_Task_3.layout index 17b1801..3cca72d 100644 --- a/ASD_Task_3.layout +++ b/ASD_Task_3.layout @@ -2,39 +2,39 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/list.cpp b/list.cpp index fe0655c..e5cc802 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,8 +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,7 +37,8 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - your code here + delete P; + //---------------------------------------- @@ -43,8 +50,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 +68,9 @@ 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,7 +85,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); + } //---------------------------------------- @@ -83,7 +101,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 +123,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 +145,13 @@ 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,8 +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); + } //---------------------------------------- } diff --git a/list.h b/list.h index c21344f..9a91c54 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,17 @@ 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..cbc3a6c 100644 --- a/main.cpp +++ b/main.cpp @@ -21,6 +21,7 @@ int main() { void mainMenu() { address P; infotype X; + infotype H; /** * IS : List has been created * PR : prints menu to user @@ -51,8 +52,62 @@ void mainMenu() { case 1: X = create_data(); P = allocate(X); - insertFirst(L,P) + insertFirst(L,P); + H = create_data(); + insertAndSort(L,H); + + break; + case 2: + printInfo(L); + break; + case 3: + cout << "Masukkan ID: "; + cin >> H.ID; + P = findElm(L, H); + if (P != NULL) + { + view_data(info(P)); + } + else + { + cout << "ID Data yang anda cari tidak ada\n"; + } + break; + case 4: + cout << "Masukkan ID: "; + cin >> H.ID; + P = findElm(L, H); + if (P != NULL) + { + edit_data(info(P)); + } + else + { + cout << "ID Data yang anda cari tidak ada\n"; + } + break; + case 5: + cout << "Masukkan ID: "; + cin >> H.ID; + if (findElm(L, H) != NULL) + { + deletebyID(L, H.ID); + } + else + { + cout << "Not Found" << endl; + } + break; + case 6: + savePassedMember(L, L_passed); + cout<<"Member yang LULUS udah selesai"<>d.ID; + cout<<"Masukkan Nama ; "; + cin>>d.name; + cout<<"Masukkan Ranking ; "; + cin>>d.rank; + cout<<"Masukkan Score ; "; + cin>>d.score; @@ -32,8 +42,11 @@ void view_data(mytype d) { // =========================== // YOUR CODE HERE - your code here - + cout<<"ID Member : "<>d.name; + cout<<"Masukkan Rank Pengganti : "; + cin>>d.rank; + cout<<"Masukkan Score Pengganti : "; + cin>>d.score; diff --git a/my_data.h b/my_data.h index 2937b48..9b63831 100644 --- a/my_data.h +++ b/my_data.h @@ -5,9 +5,9 @@ using namespace std; /** - CLASS : - NAME : - STUDENT ID : + CLASS : IF - 43 - 05 + NAME : Hazim Isma'il + STUDENT ID : 1301194149 **/ struct mytype { @@ -20,8 +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 +31,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 diff --git a/obj/Debug/list.o b/obj/Debug/list.o new file mode 100644 index 0000000..5a50397 Binary files /dev/null and b/obj/Debug/list.o differ diff --git a/obj/Debug/my_data.o b/obj/Debug/my_data.o new file mode 100644 index 0000000..a12e72a Binary files /dev/null and b/obj/Debug/my_data.o differ diff --git a/operation.cpp b/operation.cpp index c2dc0b0..faab5c9 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,19 @@ void insertAndSort(List &L, infotype x) { */ //-------------your code here------------- - your code here + address Prec; + Prec = first(L); + if (Prec == NULL || info(first(L)).ID >= x.ID){ + insertFirst(L, allocate(x)); + }else if(info(last(L)).ID < x.ID){ + insertLast(L, allocate(x)); + }else{ + while(Prec != NULL && info(Prec).ID = 80){ + insertFirst(L2, allocate(info(P))); + } + P = next(P); + } //---------------------------------------- }