diff --git a/ASD_Task_3.depend b/ASD_Task_3.depend index 831bfcc..75ac545 100644 --- a/ASD_Task_3.depend +++ b/ASD_Task_3.depend @@ -52,3 +52,31 @@ "operation.h" "my_data.h" +1582029680 source:c:\users\rulz\documents\github\asd_task_3\my_data.cpp + "my_data.h" + +1582029833 c:\users\rulz\documents\github\asd_task_3\my_data.h + + +1582030192 source:c:\users\rulz\documents\github\asd_task_3\list.cpp + "list.h" + "my_data.h" + +1582028654 c:\users\rulz\documents\github\asd_task_3\list.h + + "my_data.h" + +1582030314 source:c:\users\rulz\documents\github\asd_task_3\operation.cpp + "list.h" + "operation.h" + "my_data.h" + +1582028356 c:\users\rulz\documents\github\asd_task_3\operation.h + "list.h" + +1582030322 source:c:\users\rulz\documents\github\asd_task_3\main.cpp + + "list.h" + "operation.h" + "my_data.h" + diff --git a/bin/Debug/ASD_Task_3.exe b/bin/Debug/ASD_Task_3.exe new file mode 100644 index 0000000..17ccf45 Binary files /dev/null and b/bin/Debug/ASD_Task_3.exe differ diff --git a/list.cpp b/list.cpp index fe0655c..2f6ab03 100644 --- a/list.cpp +++ b/list.cpp @@ -6,7 +6,7 @@ void createList(List &L) { * FS : set first(L) and last(L) with Null */ //-------------your code here------------- - your code here + first(L) = NULL; //---------------------------------------- @@ -19,7 +19,9 @@ address allocate(infotype x) { address P; //-------------your code here------------- - your code here + P = new elmlist; + info(P) = x; + next(P) = NULL; //---------------------------------------- @@ -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,12 @@ 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); + first(L) = P; + } else{ + first(L) = P; + } //---------------------------------------- @@ -55,7 +62,19 @@ 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){ + address Q = first(L); + while ( next(Q)!= NULL) + { + Q=next(Q); + } + next(Q)=P; + } + else + { + insertFirst(L,P); + } + //---------------------------------------- @@ -67,10 +86,25 @@ address findElm(List L, infotype x) { * FS : returns element with info.ID = x.ID, return Null if such ID is not found */ - + int ID; address P; //-------------your code here------------- - your code here + P = first(L); + while (P != NULL) + { + if (info(P).ID != x.ID) + { + P= next(P); + } + else if (info(P).ID == x.ID) + { + return P; + } + else + { + return NULL; + } + } //---------------------------------------- @@ -83,12 +117,21 @@ 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) != NULL){ + P= first(L); + first(L)=next(P); + next(P)=NULL; + } + else + { + first(L)= NULL; + } + } //---------------------------------------- -} + void deleteLast(List &L, address &P) { /** @@ -96,12 +139,24 @@ 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 = first(L); + if (first(L)!= NULL) + { + while (next(next(P)) != NULL){ + P = next(P); + } + next(P)= NULL; + } + else + { + first(L)=NULL; + } + } //---------------------------------------- -} + void printInfo(List L) { /** @@ -109,7 +164,22 @@ 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; + if (first(L) != NULL) + { + P = first(L); + while (P != NULL) + { + cout << "======================================="< * -* Type List : < -* first : address -* last : address +* Type List : < +* first : address +* last : address * > * **/ @@ -37,13 +37,14 @@ typedef struct elmlist *address; struct elmlist{ //------------- your code here ----------- - + infotype info; + address next; //---------------------------------------- }; struct List{ //------------- your code here ----------- - + address first; //---------------------------------------- }; diff --git a/main.cpp b/main.cpp index 9e0b483..0d6e9c8 100644 --- a/main.cpp +++ b/main.cpp @@ -51,7 +51,7 @@ void mainMenu() { case 1: X = create_data(); P = allocate(X); - insertFirst(L,P) + insertFirst(L,P); break; } } while(true); diff --git a/my_data.cpp b/my_data.cpp index 68b9d77..7fe3c85 100644 --- a/my_data.cpp +++ b/my_data.cpp @@ -1,10 +1,10 @@ - + #include "my_data.h" /** - CLASS : - NAME : - STUDENT ID : + CLASS : IF-43-05 + NAME : MUHAMMAD KHIYARUS SYIAM + STUDENT ID : 1301194242 **/ mytype create_data() { @@ -15,7 +15,15 @@ mytype create_data() { mytype d; // =========================== // YOUR CODE HERE - your code here + cout << "ID anda : "; + cin >> d.ID; + cout << "Nama anda : "; + cin >> d.name; + cout << "Rangking anda : "; + cin >> d.ranking; + cout << "Score anda : "; + cin >> d.score; + @@ -32,7 +40,10 @@ void view_data(mytype d) { // =========================== // YOUR CODE HERE - your code here + cout << "ID : " << d.ID << endl; + cout << "Nama : " << d.name << endl; + cout << "Rank : " << d.ranking << endl; + cout << "Score : " << d.score << endl; @@ -50,7 +61,19 @@ void edit_data(mytype &d) { // =========================== // YOUR CODE HERE - your code here + cout <<"ID : "<< d.ID<> d.name; + cout << "Ranking Baru : "; + cin >> d.ranking; + cout << "Score Baru : "; + cin >> d.score; diff --git a/my_data.h b/my_data.h index 2937b48..d5fa105 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 : MUHAMMAD KHIYARUS SYIAM + STUDENT ID : 1301194242 **/ struct mytype { @@ -20,7 +20,10 @@ struct mytype { */ //================================================= // YOUR CODE STARTS HERE - your code here + int ID; + string name; + int ranking; + 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..cbfb8f6 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..c9c6cee 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..30141af 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..341d1eb Binary files /dev/null and b/obj/Debug/operation.o differ diff --git a/operation.cpp b/operation.cpp index c2dc0b0..34df42b 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,33 @@ void insertAndSort(List &L, infotype x) { */ //-------------your code here------------- - your code here + address P; + address Q; + P = allocate(x); + if(first(L) == NULL) { + insertFirst(L,P); + } else { + Q = findElm(L,info(P)); + if (Q == NULL) { + address last = first(L); + while (next(last) != NULL) { + last = next(last); + } + if(info(P).ID <= info(first(L)).ID) { + insertFirst(L,P); + } else if (info(P).ID >= info(first(L)).ID) { + insertLast(L,P); + } else { + Q = first(L); + while (info(next(Q)).ID < info(P).ID) { + Q = next(Q); + } + insertAfter(L,Q,P); + } + } else { + cout<<"ID Duplikat"< 80) { + insertAndSort(L2,info(P)); + } else { + insertAndSort(tmp,info(P)); + } + } + L = tmp; //----------------------------------------