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

1301190381 || VINCENT WILLIAMS JONATHAN || IF - 43 - 05 #169

Open
wants to merge 3 commits 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
29 changes: 29 additions & 0 deletions ASD_Task_3.depend
Original file line number Diff line number Diff line change
Expand Up @@ -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
<iostream>
"my_data.h"

1582301798 /home/vincent/Documents/Struktur Data/ASD_Task_3/my_data.h
<iostream>

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

28 changes: 14 additions & 14 deletions ASD_Task_3.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="my_data.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="list.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="496" topLine="7" />
<Cursor1 position="774" topLine="0" />
</Cursor>
</File>
<File name="operation.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="288" topLine="0" />
<Cursor1 position="204" topLine="0" />
</Cursor>
</File>
<File name="list.cpp" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="my_data.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2862" topLine="116" />
<Cursor1 position="46" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="my_data.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1006" topLine="0" />
<Cursor1 position="197" topLine="0" />
</Cursor>
</File>
<File name="my_data.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="operation.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="774" topLine="0" />
<Cursor1 position="207" topLine="0" />
</Cursor>
</File>
<File name="list.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="operation.cpp" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="688" topLine="17" />
<Cursor1 position="2010" topLine="0" />
</Cursor>
</File>
<File name="operation.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="list.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="207" topLine="0" />
<Cursor1 position="2014" topLine="97" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file added bin/Debug/ASD_Task_3
Binary file not shown.
136 changes: 93 additions & 43 deletions list.cpp
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
//----------------------------------------
}

14 changes: 8 additions & 6 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ using namespace std;
* prev : address
* >
*
* Type List : <
* first : address
* last : address
* Type List : <
* first : address
* last : address
* >
*
**/
Expand All @@ -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;
//----------------------------------------
};

Expand Down
Loading