Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YUSUF KAMAL_1301190464_IF-43-05 #291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ASD_Task_2.depend
Original file line number Diff line number Diff line change
Expand Up @@ -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
<iostream>

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
<iostream>
"list.h"
"operation.h"

20 changes: 10 additions & 10 deletions ASD_Task_2.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="operation.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="operation.cpp" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="656" topLine="0" />
<Cursor1 position="508" topLine="7" />
</Cursor>
</File>
<File name="Main.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="list.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="837" topLine="23" />
<Cursor1 position="3867" topLine="131" />
</Cursor>
</File>
<File name="list.h" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="Main.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="151" topLine="0" />
<Cursor1 position="837" topLine="23" />
</Cursor>
</File>
<File name="list.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="operation.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="214" topLine="117" />
<Cursor1 position="152" topLine="0" />
</Cursor>
</File>
<File name="operation.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="list.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="152" topLine="0" />
<Cursor1 position="713" topLine="27" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file added bin/Debug/ASD_Task_2.exe
Binary file not shown.
77 changes: 45 additions & 32 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ void createList(List &L) {
* FS : set first(L) with Null
*/
//-------------your code here-------------
cout<<"your code here"<<endl;
L.first = NULL;


//----------------------------------------
Expand All @@ -16,10 +16,10 @@ address allocate(infotype x) {
* FS : return new list element with info = x and next element is Null
*/

address P = NULL;
address P = new elmlist;
//-------------your code here-------------
cout<<"your code here"<<endl;

P -> info = x;
P -> next = NULL;

//----------------------------------------
return P;
Expand All @@ -30,9 +30,7 @@ void deallocate(address &P) {
* FS : delete element pointed by P
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


delete P;
//----------------------------------------
}

Expand All @@ -42,10 +40,8 @@ void insertFirst(List &L, address P) {
* FS : element pointed by P became the first element in List L
*/
//-------------your code here-------------
cout<<"your code here"<<endl;



P -> next = L.first;
L.first = P;
//----------------------------------------
}

Expand All @@ -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"<<endl;


address Q;
Q = L.first;
while(Q -> next != NULL){
Q = Q -> next;
}
Q -> next = P;
//----------------------------------------
}

Expand All @@ -70,11 +69,15 @@ address findElm(List L, infotype x) {

address P;
//-------------your code here-------------
cout<<"your code here"<<endl;
P = L.first;
while (P != NULL && P->info != x)
{
P = P -> next;
}
return P;


//----------------------------------------
return P;
}

void deleteFirst(List &L, address &P) {
Expand All @@ -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"<<endl;



if (L.first != NULL){
P = L.first;
L.first = P -> next;
P -> next = NULL;
}
//----------------------------------------
}

Expand All @@ -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"<<endl;



address Q;
Q = L.first;
if (Q -> next == NULL){
deleteFirst(L,Q);
} else {
while((Q -> next)->next != NULL){
Q = Q -> next;
}
P = Q -> next;
Q -> next = NULL;
}
//----------------------------------------
}

Expand All @@ -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"<<endl;


address Q = L.first;
while (Q != NULL){
cout<<Q -> info<<", ";
Q = Q -> next;
}
//----------------------------------------
cout<<endl;
}
Expand All @@ -124,8 +137,8 @@ void insertAfter(List &L, address Prec, address P) {
* pointed by pointer Prec
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

P -> next = Prec -> next;
Prec -> next = P;
//----------------------------------------

}
Expand All @@ -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"<<endl;

P = Prec -> next;
Prec -> next = P -> next;
P -> next = NULL;

//----------------------------------------
}

7 changes: 3 additions & 4 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Binary file added obj/Debug/Main.o
Binary file not shown.
Binary file modified obj/Debug/list.o
Binary file not shown.
Binary file modified obj/Debug/operation.o
Binary file not shown.
18 changes: 17 additions & 1 deletion operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,23 @@ void insert_sorted(List &L, infotype x) {
*/

//-------------your code here-------------
cout<<"your code here"<<endl;
address Q,P;
if ((first(L) == NULL) || (x < info(first(L)))) {
P = allocate(x);
insertFirst(L,P);
} else {
Q = first(L);
while ((next(Q)!= NULL) && (x > 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);
}
}


//----------------------------------------
Expand Down