diff --git a/ASD_Task_3.depend b/ASD_Task_3.depend index 831bfcc..75cf1ea 100644 --- a/ASD_Task_3.depend +++ b/ASD_Task_3.depend @@ -52,3 +52,31 @@ "operation.h" "my_data.h" +1582373339 source:c:\users\azizah cahya\documents\github\asd_task_3\operation.cpp + "list.h" + "operation.h" + "my_data.h" + +1581658788 c:\users\azizah cahya\documents\github\asd_task_3\list.h + + "my_data.h" + +1581658788 c:\users\azizah cahya\documents\github\asd_task_3\my_data.h + + +1581658474 c:\users\azizah cahya\documents\github\asd_task_3\operation.h + "list.h" + +1582383978 source:c:\users\azizah cahya\documents\github\asd_task_3\main.cpp + + "list.h" + "operation.h" + "my_data.h" + +1582332921 source:c:\users\azizah cahya\documents\github\asd_task_3\list.cpp + "list.h" + "my_data.h" + +1582332293 source:c:\users\azizah cahya\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..eef23ab 100644 --- a/ASD_Task_3.layout +++ b/ASD_Task_3.layout @@ -2,37 +2,37 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/bin/Debug/ASD_Task_3.exe b/bin/Debug/ASD_Task_3.exe new file mode 100644 index 0000000..145663c Binary files /dev/null and b/bin/Debug/ASD_Task_3.exe differ diff --git a/list.cpp b/list.cpp index fe0655c..a9327f5 100644 --- a/list.cpp +++ b/list.cpp @@ -1,12 +1,15 @@ #include "list.h" #include "my_data.h" +using namespace std; + 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 +22,10 @@ address allocate(infotype x) { address P; //-------------your code here------------- - your code here + P = new elmlist; + info(P) = x; + next(P) = NULL; + prev(P) = NULL; //---------------------------------------- @@ -31,7 +37,7 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - your code here + delete P; //---------------------------------------- @@ -43,8 +49,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 +67,13 @@ 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){ + prev(P) = last(L); + next(last(L)) = P; + last(L) = P; + }else{ + insertFirst(L, P); + } //---------------------------------------- @@ -70,7 +88,12 @@ address findElm(List L, infotype x) { address P; //-------------your code here------------- - your code here + P = first(L); + if(first(L) != NULL){ + while((P != NULL) && (info(P).ID != x.ID)){ + P = next(P); + } + } //---------------------------------------- @@ -83,8 +106,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 - + if(first(L)== last(L)){ + first(L) = NULL; + last(L) = NULL; + }else{ + P = first(L); + first(L) = next(P); + prev(first(L)) = NULL; + next(P) = NULL; + } //---------------------------------------- @@ -96,7 +126,10 @@ 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); + last(L) = prev(P); + next(last(L)) = NULL; + prev(P) = NULL; @@ -109,7 +142,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 Q = first(L); + cout<<"Isi list: "< * -* 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; //---------------------------------------- }; diff --git a/main.cpp b/main.cpp index 9e0b483..9192c4c 100644 --- a/main.cpp +++ b/main.cpp @@ -9,7 +9,8 @@ using namespace std; void mainMenu(); List L, L_passed; -int main() { +int main() +{ createList(L); createList(L_passed); @@ -18,7 +19,8 @@ int main() { return 0; } -void mainMenu() { +void mainMenu() +{ address P; infotype X; /** @@ -35,7 +37,8 @@ void mainMenu() { */ //-------------your code here------------- int choice; - do { + do + { cout<<"Menu"<>choice; - switch(choice) { + switch(choice) + { case 1: X = create_data(); P = allocate(X); - insertFirst(L,P) + insertFirst(L, P); break; + case 2: + printInfo(L); + break; + case 3: + { + + infotype id; + cout<<"Search by ID : "; + cin>>id.ID; + cout<info.ID<info.name<info.rank<info.score<>id.ID; + address cari = findElm(L, id); + edit_data(id); + info(cari) = id; + } + break; + + case 5 : + { + infotype b; + address Search; + cout<<"Search by ID : "; + cin>>b.ID; + Search = findElm(L, b); + if(Search == first(L)) + { + deleteFirst(L, Search); + } + else if(Search == last(L)) + { + deleteLast(L, Search); + } + else + { + deleteAfter(L, prev(Search), Search); + } + cout<<"DATA TELAH TERHAPUS"<>d.ID; + cout<<"Name : "; + cin>>d.name; + cout<<"Rank : "; + cin>>d.rank; + cout<<"Score : "; + cin>>d.score; @@ -32,7 +39,12 @@ void view_data(mytype d) { // =========================== // YOUR CODE HERE - your code here + cout<<" ID : "<>d.name; + cout<<"New Rank : "; + cin>>d.rank; + cout<<"New Score : "; + cin>>d.score; // =========================== } - diff --git a/my_data.h b/my_data.h index 2937b48..b6b572e 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 : AZIZAH CAHYA KEMILA + STUDENT ID : 1301194103 **/ struct mytype { @@ -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 diff --git a/obj/Debug/list.o b/obj/Debug/list.o new file mode 100644 index 0000000..975d133 Binary files /dev/null and b/obj/Debug/list.o differ diff --git a/obj/Debug/main.o b/obj/Debug/main.o new file mode 100644 index 0000000..e119624 Binary files /dev/null and b/obj/Debug/main.o differ diff --git a/obj/Debug/my_data.o b/obj/Debug/my_data.o new file mode 100644 index 0000000..b56670f Binary files /dev/null and b/obj/Debug/my_data.o differ diff --git a/obj/Debug/operation.o b/obj/Debug/operation.o new file mode 100644 index 0000000..786e842 Binary files /dev/null and b/obj/Debug/operation.o differ diff --git a/operation.cpp b/operation.cpp index c2dc0b0..0dbef85 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,13 +14,27 @@ void insertAndSort(List &L, infotype x) { */ //-------------your code here------------- - your code here - - + address P; + P = allocate(x); + if(first(L) == NULL || x.ID < info(first(L)).ID){ + insertFirst(L, P); + }else{ + address Q = first(L); + while(next(Q) != NULL && x.ID >= info(next(Q)).ID){ + Q = next(Q); + } + if(info(Q).ID == x.ID){ + cout<<"ID SUDAH ADA"; + }else if(next(Q) == NULL){ + insertLast(L, P); + }else if(info(Q).ID != x.ID){ + insertAfter(L, Q, P); + } + } + cout< 80){ + address Q; + Q = allocate(info(P)); + insertLast(L2, Q); + } + P = next(P); + } //---------------------------------------- } +