diff --git a/ASD_Task_3.depend b/ASD_Task_3.depend index 831bfcc..c296292 100644 --- a/ASD_Task_3.depend +++ b/ASD_Task_3.depend @@ -52,3 +52,31 @@ "operation.h" "my_data.h" +1582384766 source:c:\users\user\documents\github\asd_task_3\list.cpp + "list.h" + "my_data.h" + +1582376618 c:\users\user\documents\github\asd_task_3\list.h + + "my_data.h" + +1582376490 c:\users\user\documents\github\asd_task_3\my_data.h + + +1582389589 source:c:\users\user\documents\github\asd_task_3\operation.cpp + "list.h" + "operation.h" + "my_data.h" + +1582375756 c:\users\user\documents\github\asd_task_3\operation.h + "list.h" + +1582390159 source:c:\users\user\documents\github\asd_task_3\main.cpp + + "list.h" + "operation.h" + "my_data.h" + +1582390220 source:c:\users\user\documents\github\asd_task_3\my_data.cpp + "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..1f99e74 Binary files /dev/null and b/bin/Debug/ASD_Task_3.exe differ diff --git a/list.cpp b/list.cpp index fe0655c..6b65c9e 100644 --- a/list.cpp +++ b/list.cpp @@ -6,9 +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,9 +18,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,9 +34,7 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - your code here - - + delete P; //---------------------------------------- } @@ -43,9 +44,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 && last(L) == NULL){ + first(L) = P; + last(L) = P; + } else { + next(P) = first(L); + prev(first(L)) = P; + first(L) = P; + } //---------------------------------------- } @@ -55,9 +61,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 && last(L) == NULL){ + insertFirst(L, P); + } else { + prev(P) = last(L); + next(last(L)) = P; + last(L) = P; + } //---------------------------------------- } @@ -68,11 +78,11 @@ address findElm(List L, infotype x) { return Null if such ID is not found */ - address P; + address P = first(L); //-------------your code here------------- - your code here - - + if(P != NULL && info(P).ID == x.ID){ + P = next(P); + } //---------------------------------------- return P; } @@ -83,10 +93,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 { + P = first(L); + first(L) = next(P); + next(P) = NULL; + prev(first(L)) = NULL; + } //---------------------------------------- } @@ -96,10 +112,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,13 +125,15 @@ 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){ + cout< * -* 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; //---------------------------------------- }; @@ -67,5 +69,4 @@ void deleteAfter(List&L, address Prec, address &P); address findElm(List L, infotype x); void printInfo(List L); - #endif // LIST_H_INCLUDED diff --git a/main.cpp b/main.cpp index 9e0b483..426c36a 100644 --- a/main.cpp +++ b/main.cpp @@ -51,10 +51,52 @@ void mainMenu() { case 1: X = create_data(); P = allocate(X); - insertFirst(L,P) + if(findElm(L, info(P)) == NULL){ + insertFirst(L,P); + } + break; + case 2: + printInfo(L); + break; + case 3: + cout<<"ID that you want to know: "; + cin>>X.ID; + P = findElm(L, X); + if(P != NULL){ + view_data(info(P)); + } else { + cout<<"Data doesn't exist"<>X.ID; + P = findElm(L, X); + if(P != NULL) { + edit_data(info(P)); + } else { + cout<<"Data doesn't exist"<>X.ID; + if(findElm(L, X) != NULL){ + deletebyID(L, X.ID); + } else { + cout<<"Data doesn't exist"<>d.ID; + cout<<"Your name: "; + cin>>d.name; + cout<<"Your rank: "; + cin>>d.rank; + cout<<"Your score: "; + cin>>d.score; // =========================== return d; } @@ -32,15 +35,15 @@ void view_data(mytype d) { // =========================== // YOUR CODE HERE - your code here - - - - + cout<<"=============================="<>d.name; + cout<>d.rank; + cout<>d.score; + cout< info(Q).ID){ + Q = next(Q); + } + if(next(Q) == NULL){ + insertLast(L, P); + } else { + insertAfter(L, Q, P); + } + } //---------------------------------------- } - void deletebyID(List &L, int id_x) { /** * IS : List L may be empty @@ -29,13 +40,20 @@ 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(first(L) != last(L) && id_x == info(P).ID){ + deleteAfter(L, prev(P), P); + } + P = next(P); + } + } //---------------------------------------- } - void savePassedMember(List &L, List &L2){ /** * IS : List L and L2 may be empty @@ -43,8 +61,21 @@ 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); + } + } //---------------------------------------- }