diff --git a/ASD_Task_2.depend b/ASD_Task_2.depend index 4a87b2d..90c1e87 100644 --- a/ASD_Task_2.depend +++ b/ASD_Task_2.depend @@ -29,3 +29,21 @@ "list.h" "operation.h" +1581170938 source:d:\kuliah\semester 2\asd_task_2\operation.cpp + "list.h" + "operation.h" + +1580809364 d:\kuliah\semester 2\asd_task_2\list.h + + +1580808708 d:\kuliah\semester 2\asd_task_2\operation.h + "list.h" + +1581170877 source:d:\kuliah\semester 2\asd_task_2\main.cpp + + "list.h" + "operation.h" + +1581170715 source:d:\kuliah\semester 2\asd_task_2\list.cpp + "list.h" + diff --git a/ASD_Task_2.layout b/ASD_Task_2.layout index e69ac9c..51663f5 100644 --- a/ASD_Task_2.layout +++ b/ASD_Task_2.layout @@ -4,22 +4,22 @@ - + - + - + - + - + - + - + diff --git a/Main.cpp b/Main.cpp index 297d6ca..ec0a239 100644 --- a/Main.cpp +++ b/Main.cpp @@ -34,7 +34,7 @@ int main() { //================================================== // TEST INSERT AFTER P = findElm(L, 6); - insertLast(L, allocate(5)); + insertAfter(L, P , allocate(5) ); printInfo(L); cout<<"output should be: 8, 3, 6, 5, 4, 2,"< 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,8 +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..be28827 100644 --- a/list.h +++ b/list.h @@ -30,14 +30,14 @@ typedef struct elmlist *address; struct elmlist{ //------------- your code here ----------- - - + infotype info; + address next; //---------------------------------------- }; struct List{ //------------- your code here ----------- - + address first; //---------------------------------------- }; diff --git a/obj/Debug/Main.o b/obj/Debug/Main.o new file mode 100644 index 0000000..2838b6d 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..201ee28 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..d706d5e 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..a829012 100644 --- a/operation.cpp +++ b/operation.cpp @@ -13,8 +13,17 @@ void insert_sorted(List &L, infotype x) { */ //-------------your code here------------- - cout<<"your code here"<info > x) { + insertFirst(L, allocate(x)); + } else if (findElm(L, x) == NULL) { + while (P != NULL && P->info < x) { + Q = P; + P = P->next; + } + insertAfter(L, Q, allocate(x)); + } //---------------------------------------- }