diff --git a/ASD_Task_2.depend b/ASD_Task_2.depend index 4a87b2d..d2e22b9 100644 --- a/ASD_Task_2.depend +++ b/ASD_Task_2.depend @@ -29,3 +29,21 @@ "list.h" "operation.h" +1581312147 source:c:\users\asus\documents\github\asd_task_2\operation.cpp + "list.h" + "operation.h" + +1581313738 c:\users\asus\documents\github\asd_task_2\list.h + + +1581312147 c:\users\asus\documents\github\asd_task_2\operation.h + "list.h" + +1581313677 source:c:\users\asus\documents\github\asd_task_2\list.cpp + "list.h" + +1581312147 source:c:\users\asus\documents\github\asd_task_2\main.cpp + + "list.h" + "operation.h" + diff --git a/ASD_Task_2.layout b/ASD_Task_2.layout index e69ac9c..2d2a817 100644 --- a/ASD_Task_2.layout +++ b/ASD_Task_2.layout @@ -2,29 +2,29 @@ - + - + - + - + - + - + - + - + - + - + diff --git a/bin/Debug/ASD_Task_2.exe b/bin/Debug/ASD_Task_2.exe new file mode 100644 index 0000000..25d1ad6 Binary files /dev/null and b/bin/Debug/ASD_Task_2.exe differ diff --git a/list.cpp b/list.cpp index f61d73d..b68a06e 100644 --- a/list.cpp +++ b/list.cpp @@ -5,7 +5,7 @@ void createList(List &L) { * FS : set first(L) with Null */ //-------------your code here------------- - cout<<"your code here"< info = x; + P -> next = NULL; //---------------------------------------- return P; @@ -30,9 +30,7 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - cout<<"your code here"< next = L.first; + L.first = P; //---------------------------------------- } @@ -55,9 +51,12 @@ void insertLast(List &L, address P) { * FS : element pointed by P became the last element in List L */ //-------------your code here------------- - cout<<"your code here"< next != NULL){ + Q = Q -> next; + } + Q -> next = P; //---------------------------------------- } @@ -70,11 +69,15 @@ address findElm(List L, infotype x) { address P; //-------------your code here------------- - cout<<"your code here"<info != x) + { + P = P -> next; + } + return P; //---------------------------------------- - return P; } void deleteFirst(List &L, address &P) { @@ -83,10 +86,11 @@ void deleteFirst(List &L, address &P) { * FS : first element in List L is removed and is pointed by P */ //-------------your code here------------- - cout<<"your code here"< next; + P -> next = NULL; + } //---------------------------------------- } @@ -96,10 +100,17 @@ void deleteLast(List &L, address &P) { * FS : last element in List L is removed and is pointed by P */ //-------------your code here------------- - cout<<"your code here"< next == NULL){ + deleteFirst(L,Q); + } else { + while((Q -> next)->next != NULL){ + Q = Q -> next; + } + P = Q -> next; + Q -> next = NULL; + } //---------------------------------------- } @@ -109,9 +120,11 @@ void printInfo(List L) { * call the view_data function from my_data.h to print the info */ //-------------your code here------------- - cout<<"your code here"< info<<", "; + Q = Q -> next; + } //---------------------------------------- cout< next = Prec -> next; + Prec -> next = P; //---------------------------------------- } @@ -136,9 +149,9 @@ void deleteAfter(List &L, address Prec, address &P) { * is removed and pointed by pointer P */ //-------------your code here------------- - cout<<"your code here"< next; + Prec -> next = P -> next; + P -> next = NULL; //---------------------------------------- } - diff --git a/list.h b/list.h index d021225..04dad87 100644 --- a/list.h +++ b/list.h @@ -30,19 +30,18 @@ typedef struct elmlist *address; struct elmlist{ //------------- your code here ----------- - - + infotype info; + address next; //---------------------------------------- }; struct List{ //------------- your code here ----------- - + address first; //---------------------------------------- }; - // define a function and a procedure to allocate and deallocate an element list void createList(List &L); address allocate(infotype x); diff --git a/obj/Debug/Main.o b/obj/Debug/Main.o new file mode 100644 index 0000000..6c2ae73 Binary files /dev/null and b/obj/Debug/Main.o differ diff --git a/obj/Debug/list.o b/obj/Debug/list.o index f0e2f8e..8f9a94c 100644 Binary files a/obj/Debug/list.o and b/obj/Debug/list.o differ diff --git a/obj/Debug/operation.o b/obj/Debug/operation.o index b08b1f9..14c0942 100644 Binary files a/obj/Debug/operation.o and b/obj/Debug/operation.o differ diff --git a/operation.cpp b/operation.cpp index 0a0e067..dd6481d 100644 --- a/operation.cpp +++ b/operation.cpp @@ -13,7 +13,23 @@ void insert_sorted(List &L, infotype x) { */ //-------------your code here------------- - cout<<"your code here"< info(next(Q)))){ + Q = next(Q); + } + if (next(Q) == NULL){ + P = allocate(x); + insertLast(L,P); + }else if (info(P)!=info(Q)){ + P = allocate(x); + insertAfter(L,P,Q); + } + } //----------------------------------------