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"

1582373339 source:c:\users\azizah cahya\documents\github\asd_task_3\operation.cpp
"list.h"
"operation.h"
"my_data.h"

1581658788 c:\users\azizah cahya\documents\github\asd_task_3\list.h
<iostream>
"my_data.h"

1581658788 c:\users\azizah cahya\documents\github\asd_task_3\my_data.h
<iostream>

1581658474 c:\users\azizah cahya\documents\github\asd_task_3\operation.h
"list.h"

1582383978 source:c:\users\azizah cahya\documents\github\asd_task_3\main.cpp
<iostream>
"list.h"
"operation.h"
"my_data.h"

1582332921 source:c:\users\azizah cahya\documents\github\asd_task_3\list.cpp
"list.h"
"my_data.h"

1582332293 source:c:\users\azizah cahya\documents\github\asd_task_3\my_data.cpp
"my_data.h"

26 changes: 13 additions & 13 deletions ASD_Task_3.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@
<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.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="496" topLine="7" />
<Cursor1 position="3308" topLine="132" />
</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="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="288" topLine="0" />
<Cursor1 position="2692" topLine="21" />
</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="53" />
</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.cpp" 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="288" topLine="29" />
</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="my_data.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="774" topLine="0" />
<Cursor1 position="608" 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="my_data.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="926" topLine="27" />
</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="operation.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="207" topLine="0" />
</Cursor>
Expand Down
Binary file added bin/Debug/ASD_Task_3.exe
Binary file not shown.
71 changes: 58 additions & 13 deletions list.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include "list.h"
#include "my_data.h"

using namespace std;

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,7 +22,10 @@ address allocate(infotype x) {

address P;
//-------------your code here-------------
your code here
P = new elmlist;
info(P) = x;
next(P) = NULL;
prev(P) = NULL;


//----------------------------------------
Expand All @@ -31,7 +37,7 @@ void deallocate(address &P) {
* FS : delete element pointed by P
*/
//-------------your code here-------------
your code here
delete P;


//----------------------------------------
Expand All @@ -43,8 +49,14 @@ 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){
next(P) = first(L);
prev(first(L)) = P;
first(L) = P;
}else {
first(L) = P;
last(L) = P;
}

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


//----------------------------------------
Expand All @@ -70,7 +88,12 @@ address findElm(List L, infotype x) {

address P;
//-------------your code here-------------
your code here
P = first(L);
if(first(L) != NULL){
while((P != NULL) && (info(P).ID != x.ID)){
P = next(P);
}
}


//----------------------------------------
Expand All @@ -83,8 +106,15 @@ 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)){
first(L) = NULL;
last(L) = NULL;
}else{
P = first(L);
first(L) = next(P);
prev(first(L)) = NULL;
next(P) = NULL;
}


//----------------------------------------
Expand All @@ -96,7 +126,10 @@ 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
P = last(L);
last(L) = prev(P);
next(last(L)) = NULL;
prev(P) = NULL;



Expand All @@ -109,7 +142,12 @@ void printInfo(List L) {
* call the view_data function from my_data.h to print the info
*/
//-------------your code here-------------
your code here
address Q = first(L);
cout<<"Isi list: "<<endl;
while(Q != NULL){
view_data(info(Q));
Q = next(Q);
}


//----------------------------------------
Expand All @@ -123,7 +161,10 @@ void insertAfter(List &L, address Prec, address P) {
* pointed by pointer Prec
*/
//-------------your code here-------------
your code here
next(P)= next(Prec);
prev(P) = Prec;
prev(next(Prec)) = P;
next(Prec) = P;

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

Expand All @@ -135,7 +176,11 @@ void deleteAfter(List &L, address Prec, address &P) {
* 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;


//----------------------------------------
Expand Down
13 changes: 8 additions & 5 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,13 +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
89 changes: 83 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ using namespace std;
void mainMenu();
List L, L_passed;

int main() {
int main()
{
createList(L);
createList(L_passed);

Expand All @@ -18,7 +19,8 @@ int main() {
return 0;
}

void mainMenu() {
void mainMenu()
{
address P;
infotype X;
/**
Expand All @@ -35,7 +37,8 @@ void mainMenu() {
*/
//-------------your code here-------------
int choice;
do {
do
{
cout<<"Menu"<<endl;
cout<<"1. insert"<<endl;
cout<<"2. view member"<<endl;
Expand All @@ -47,14 +50,88 @@ void mainMenu() {
cout<<"0. exit"<<endl;
cout<<"input choice: ";
cin>>choice;
switch(choice) {
switch(choice)
{
case 1:
X = create_data();
P = allocate(X);
insertFirst(L,P)
insertFirst(L, P);
break;
case 2:
printInfo(L);
break;
case 3:
{

infotype id;
cout<<"Search by ID : ";
cin>>id.ID;
cout<<endl;
address a = findElm(L, id);
if( a == NULL)
{
cout<<"NOT FOUND"<<endl;
}
else
{
cout<<"----DATA----"<<endl;
cout<<" ID : "<<a->info.ID<<endl;
cout<<" Name : "<<a->info.name<<endl;
cout<<" Rank : "<<a->info.rank<<endl;
cout<<" Score : "<<a->info.score<<endl;
}
}
break;
case 4:
{
infotype id;
cout<<"Search by ID : ";
cin>>id.ID;
address cari = findElm(L, id);
edit_data(id);
info(cari) = id;
}
break;

case 5 :
{
infotype b;
address Search;
cout<<"Search by ID : ";
cin>>b.ID;
Search = findElm(L, b);
if(Search == first(L))
{
deleteFirst(L, Search);
}
else if(Search == last(L))
{
deleteLast(L, Search);
}
else
{
deleteAfter(L, prev(Search), Search);
}
cout<<"DATA TELAH TERHAPUS"<<endl;
}
} while(true);
break;
case 6 :
{
savePassedMember(L, L_passed);

}
break;
case 7 :
{
printInfo(L_passed);
}
break;

}
cout<<endl;
}
while(choice != 0);


//----------------------------------------
}
Loading