diff --git a/ASD_Task_3.depend b/ASD_Task_3.depend index 831bfcc..42419d7 100644 --- a/ASD_Task_3.depend +++ b/ASD_Task_3.depend @@ -52,3 +52,32 @@ "operation.h" "my_data.h" +1582379486 source:/home/vincent/Documents/Struktur Data/ASD_Task_3/list.cpp + "list.h" + "my_data.h" + +1582288083 /home/vincent/Documents/Struktur Data/ASD_Task_3/list.h + + "my_data.h" + +1582301798 /home/vincent/Documents/Struktur Data/ASD_Task_3/my_data.h + + +1582301767 source:/home/vincent/Documents/Struktur Data/ASD_Task_3/my_data.cpp + "my_data.h" + +1582383095 source:/home/vincent/Documents/Struktur Data/ASD_Task_3/operation.cpp + "list.h" + "operation.h" + "my_data.h" + +1582287934 /home/vincent/Documents/Struktur Data/ASD_Task_3/operation.h + "list.h" + +1582379568 source:/home/vincent/Documents/Struktur Data/ASD_Task_3/main.cpp + + + "list.h" + "operation.h" + "my_data.h" + diff --git a/ASD_Task_3.layout b/ASD_Task_3.layout index 17b1801..e786836 100644 --- a/ASD_Task_3.layout +++ b/ASD_Task_3.layout @@ -2,39 +2,39 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/bin/Debug/ASD_Task_3 b/bin/Debug/ASD_Task_3 new file mode 100755 index 0000000..4a5e805 Binary files /dev/null and b/bin/Debug/ASD_Task_3 differ diff --git a/list.cpp b/list.cpp index fe0655c..74ef071 100644 --- a/list.cpp +++ b/list.cpp @@ -1,67 +1,84 @@ #include "list.h" #include "my_data.h" -void createList(List &L) { +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; //---------------------------------------- } -address allocate(infotype x) { +address allocate(infotype x) +{ /** * FS : return new list element with info = x and next element is Null */ 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; } -void deallocate(address &P) { +void deallocate(address &P) +{ /** * FS : delete element pointed by P */ //-------------your code here------------- - your code here - - + delete P; //---------------------------------------- } -void insertFirst(List &L, address P) { +void insertFirst(List &L, address P) +{ /** * IS : List L may be empty * 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; + } //---------------------------------------- } -void insertLast(List &L, address P) { +void insertLast(List &L, address P) +{ /** * IS : List L may be empty * 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; //---------------------------------------- } -address findElm(List L, infotype x) { +address findElm(List L, infotype x) +{ /** * IS : List L may be empty * FS : returns element with info.ID = x.ID, @@ -70,74 +87,107 @@ 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; } -void deleteFirst(List &L, address &P) { +void deleteFirst(List &L, address &P) +{ /** * IS : List L may be empty * 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; + } //---------------------------------------- } -void deleteLast(List &L, address &P) { +void deleteLast(List &L, address &P) +{ /** * IS : List L may be empty * 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; + } //---------------------------------------- } -void printInfo(List L) { +void printInfo(List L) +{ /** * FS : view info of all element inside 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; //---------------------------------------- } -void insertAfter(List &L, address Prec, address P) { +void insertAfter(List &L, address Prec, address P) +{ /** * IS : Prec and P is not NULL * FS : element pointed by P is placed behind the element * pointed by pointer Prec */ //-------------your code here------------- - your code here - + next(P) = next(Prec); + prev(P) = Prec; + prev(next(Prec)) = P; + next(Prec) = P; //---------------------------------------- } -void deleteAfter(List &L, address Prec, address &P) { +void deleteAfter(List &L, address Prec, address &P) +{ /** * IS : Prec is not NULL * FS : element which was before behind an element pointed by Prec * 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..2005057 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ #include +#include #include "list.h" #include "operation.h" #include "my_data.h" @@ -9,7 +10,8 @@ using namespace std; void mainMenu(); List L, L_passed; -int main() { +int main() +{ createList(L); createList(L_passed); @@ -18,7 +20,8 @@ int main() { return 0; } -void mainMenu() { +void mainMenu() +{ address P; infotype X; /** @@ -35,7 +38,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) + insertAndSort(L,X); + cout<> X.ID; + P = findElm(L, X); + if (P != NULL) + { + view_data(info(P)); + } + else + { + cout << "Not Found\n"; + } + break; + case 4: + cout << "Masukkan ID: "; + cin >> X.ID; + P = findElm(L, X); + if (P != NULL) + { + edit_data(info(P)); + } + else + { + cout << "Not Found\n"; + } + break; + case 5: + cout << "Masukkan ID: "; + cin >> X.ID; + if (findElm(L, X) != NULL) + { + deletebyID(L, X.ID); + } + else + { + cout << "Not Found" << endl; + } + break; + case 6: + savePassedMember(L, L_passed); + break; + case 7: + printInfo(L_passed); + break; + default: + exit(0); } - } while(true); - + } + while(true); //---------------------------------------- } diff --git a/my_data.cpp b/my_data.cpp index 68b9d77..a04befd 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 : VINCENT WILLIAMS JONATHAN + STUDENT ID : 1301190381 **/ mytype create_data() { @@ -15,11 +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; // =========================== return d; } @@ -32,11 +35,7 @@ void view_data(mytype d) { // =========================== // YOUR CODE HERE - your code here - - - - + cout << d.ID << " - " << d.name << " - "<< d.rank << " - " << d.score << endl; // =========================== } @@ -50,11 +49,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; // =========================== } diff --git a/my_data.h b/my_data.h index 2937b48..5257e74 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 : VINCENT WILLIAMS JONATHAN + STUDENT ID : 1301190381 **/ 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..b3d4f28 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..5277fc3 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..168e5cf 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..7926117 Binary files /dev/null and b/obj/Debug/operation.o differ diff --git a/operation.cpp b/operation.cpp index c2dc0b0..745267e 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,9 +14,19 @@ void insertAndSort(List &L, infotype x) { */ //-------------your code here------------- - your code here - - + address P,Q; + P = first(L); + if (P == NULL || info(P).ID >= x.ID) { + insertFirst(L, allocate(x)); + }else if(info(last(L)).ID <= x.ID){ + insertLast(L,allocate(x)); + }else{ + while (P != NULL && info(P).ID < x.ID) { + Q = P; + P = next(P); + } + insertAfter(L, Q, allocate(x)); + } //---------------------------------------- } @@ -29,9 +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,8 +61,12 @@ void savePassedMember(List &L, List &L2){ */ address P; //-------------your code here------------- - your code here - - + P = first(L); + while (P != NULL){ + if(info(P).score >= 80){ + insertFirst(L2,allocate(info(P))); + } + P = next(P); + } //---------------------------------------- }