Skip to content
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
28 changes: 28 additions & 0 deletions ASD_Task_3.depend
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,31 @@
"operation.h"
"my_data.h"

1582385350 source:d:\tugas kuliah\github\asd_task_3\list.cpp
"list.h"
"my_data.h"

1582381225 d:\tugas kuliah\github\asd_task_3\list.h
<iostream>
"my_data.h"

1582385243 d:\tugas kuliah\github\asd_task_3\my_data.h
<iostream>

1582385547 source:d:\tugas kuliah\github\asd_task_3\main.cpp
<iostream>
"list.h"
"operation.h"
"my_data.h"

1582266085 d:\tugas kuliah\github\asd_task_3\operation.h
"list.h"

1582385561 source:d:\tugas kuliah\github\asd_task_3\my_data.cpp
"my_data.h"

1582385903 source:d:\tugas kuliah\github\asd_task_3\operation.cpp
"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="my_data.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="496" topLine="7" />
<Cursor1 position="1387" topLine="47" />
</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="my_data.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="288" topLine="0" />
<Cursor1 position="136" 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="list.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2862" topLine="116" />
<Cursor1 position="200" 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="operation.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1006" topLine="0" />
<Cursor1 position="246" 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="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="774" topLine="0" />
<Cursor1 position="3138" topLine="103" />
</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="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="688" topLine="17" />
<Cursor1 position="1609" topLine="52" />
</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="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="207" topLine="0" />
<Cursor1 position="4176" topLine="173" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file added bin/Debug/ASD_Task_3.exe
Binary file not shown.
125 changes: 101 additions & 24 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
//----------------------------------------
}

Expand All @@ -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;
}
Expand All @@ -31,8 +34,7 @@ void deallocate(address &P) {
* FS : delete element pointed by P
*/
//-------------your code here-------------
your code here

delete P;

//----------------------------------------
}
Expand All @@ -43,7 +45,17 @@ 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;
}


//----------------------------------------
Expand All @@ -55,7 +67,17 @@ 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)
{
first(L) = P;
last(L) = P;
}
else
{
prev(P) = last(L);
next(last(L)) = P;
last(L) = P;
}


//----------------------------------------
Expand All @@ -70,9 +92,11 @@ 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;
}
Expand All @@ -83,10 +107,19 @@ 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;
}
//----------------------------------------
}

Expand All @@ -96,7 +129,19 @@ 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
if (last(L) != NULL )
{
P = last(L);
last(L) = prev(P);
prev(P) = NULL;
next(last(L)) = NULL;
}
else
{
P = first(L);
first(L) = NULL;
last(L) = NULL;
}



Expand All @@ -109,8 +154,13 @@ 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)
{
view_data(info(P));
P = next(P);
}
cout<<endl;

//----------------------------------------
}
Expand All @@ -123,7 +173,21 @@ void insertAfter(List &L, address Prec, address P) {
* pointed by pointer Prec
*/
//-------------your code here-------------
your code here
if (first(L) == NULL)
{
insertFirst(L,P);
}
else if (Prec == NULL)
{
insertLast(L,P);
}
else
{
next(P) = next(Prec);
prev(P) = Prec;
prev(next(Prec)) = P;
next(Prec) = P;
}

//----------------------------------------

Expand All @@ -135,9 +199,22 @@ void deleteAfter(List &L, address Prec, address &P) {
* is removed and pointed by pointer P
*/
//-------------your code here-------------
your code here


if (first(L) == last(L) && Prec != NULL)
{
deleteFirst(L,P);
}
else if (Prec == NULL)
{
deleteLast(L,P);
}
else
{
P = next(Prec);
next(Prec) = next(P);
prev(next(P)) = Prec;
next(P) = NULL;
prev(P) = NULL;
}
//----------------------------------------
}

42 changes: 10 additions & 32 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,20 @@

using namespace std;


/**
* Type infotype : mytype
* Type address : pointer to ElmList
*
* Type ElmList <
* info : infotype
* next : address
* prev : address
* >
*
* Type List : <
* first : address
* last : address
* >
*
**/



typedef mytype infotype;
typedef struct elmlist *address;

struct elmlist{
//------------- your code here -----------

//----------------------------------------
struct elmlist
{
infotype info;
address next;
address prev;
};

struct List{
//------------- your code here -----------


//----------------------------------------
};

struct List
{
address first;
address last;
};


// define a function and a procedure to allocate and deallocate an element list
Expand Down
Loading