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

1582295937 source:d:\asd task\asd_task_3\list.cpp
"list.h"
"my_data.h"

1582297858 d:\asd task\asd_task_3\list.h
<iostream>
"my_data.h"

1582295937 d:\asd task\asd_task_3\my_data.h
<iostream>

1582297773 source:d:\asd task\asd_task_3\operation.cpp
"list.h"
"operation.h"
"my_data.h"

1582291682 d:\asd task\asd_task_3\operation.h
"list.h"

1582297961 source:d:\asd task\asd_task_3\main.cpp
<iostream>
"list.h"
"operation.h"
"my_data.h"

Binary file added bin/Debug/ASD_Task_3.exe
Binary file not shown.
122 changes: 72 additions & 50 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,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;
}

address allocate(infotype x) {
Expand All @@ -18,47 +15,47 @@ 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;
}

void deallocate(address &P) {
/**
* FS : delete element pointed by P
*/
//-------------your code here-------------
your code here


//----------------------------------------
delete 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) {
/**
* 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) {
Expand All @@ -69,11 +66,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 @@ -82,37 +79,48 @@ 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) {
/**
* 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) {
/**
* 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;
}


Expand All @@ -122,10 +130,17 @@ void insertAfter(List &L, address Prec, address P) {
* FS : element pointed by P is placed behind the element
* pointed by pointer Prec
*/
//-------------your code here-------------
your code here

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

}
void deleteAfter(List &L, address Prec, address &P) {
Expand All @@ -134,10 +149,17 @@ void deleteAfter(List &L, address Prec, address &P) {
* FS : element which was before behind an element pointed by Prec
* 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 (next(Prec) != last(L) && Prec != NULL){
P = next(Prec);
next(Prec) = next(P);
prev(next(P)) = Prec;
next(P) = NULL;
prev(P) = NULL;
} else if (Prec != NULL) {
deleteLast(L, P);
}
}

18 changes: 8 additions & 10 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 @@ -36,16 +36,14 @@ typedef mytype infotype;
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
46 changes: 43 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,50 @@ void mainMenu() {
case 1:
X = create_data();
P = allocate(X);
insertFirst(L,P)
if (findElm(L, info(P)) == NULL) {
insertFirst(L, P);
}
break;
case 2:
printInfo(L);
break;
case 3:
cout << "Input ID: ";
cin >> X.ID;
P = findElm(L, X);
if (P != NULL) {
view_data(info(P));
} else {
cout << "Not Found\n";
}
break;
case 4:
cout << "Input ID: ";
cin >> X.ID;
P = findElm(L, X);
if (P != NULL) {
edit_data(info(P));
} else {
cout << "Not Found\n";
}
break;
case 5:
cout << "Input ID: ";
cin >> X.ID;
if (findElm(L, X) != NULL) {
deletebyID(L, X.ID);
} else {
cout << "Not Found" << endl;
}
break;
case 6:
savePassedMember(L, L_passed);
break;
case 7:
printInfo(L_passed);
break;
default:
break;
}
} while(true);

//----------------------------------------
}
47 changes: 19 additions & 28 deletions my_data.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#include "my_data.h"

/**
CLASS :
NAME :
STUDENT ID :
CLASS : IF-43-05
NAME : Reyhan Fadhlurohman Arrafi
STUDENT ID : 1301190356
**/

mytype create_data() {
Expand All @@ -13,14 +13,14 @@ mytype create_data() {
and assign the value of new data
*/
mytype d;
// ===========================
// YOUR CODE HERE
your code here




// ===========================
cout<<"Input ID : ";
cin>>d.ID;
cout<<"Input Nama : ";
cin>>d.name;
cout<<"Input Ranking : ";
cin>>d.rank;
cout<<"Input Score : ";
cin>>d.score;
return d;
}

Expand All @@ -30,14 +30,7 @@ void view_data(mytype d) {
it will be called when print_info function is invoked
*/

// ===========================
// YOUR CODE HERE
your code here




// ===========================
cout<<d.ID<<" - "<<d.name<<" - "<<d.rank<<" - "<<d.score<<endl;
}


Expand All @@ -48,13 +41,11 @@ void edit_data(mytype &d) {
* the ID must NOT be modified
*/

// ===========================
// YOUR CODE HERE
your code here




// ===========================
cout<<"Input Pergantian Nama : ";
cin>>d.name;
cout<<"Input Pergantian Rank : ";
cin>>d.rank;
cout<<"Input Pergantian Score : ";
cin>>d.score;
}

Loading