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

1301194203 | Mohammad Mirza Qusyairi | IF - 43 - 05 #153

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
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"

1582092314 source:c:\users\computer\documents\github\asd_task_3\my_data.cpp
"my_data.h"

1582092003 c:\users\computer\documents\github\asd_task_3\my_data.h
<iostream>

1582094351 source:c:\users\computer\documents\github\asd_task_3\list.cpp
"list.h"
"my_data.h"

1582091930 c:\users\computer\documents\github\asd_task_3\list.h
<iostream>
"my_data.h"

1582093443 source:c:\users\computer\documents\github\asd_task_3\operation.cpp
"list.h"
"operation.h"
"my_data.h"

1582025216 c:\users\computer\documents\github\asd_task_3\operation.h
"list.h"

1582094335 source:c:\users\computer\documents\github\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.
101 changes: 76 additions & 25 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@ 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) {
/**
* FS : return new list element with info = x and next element is Null
* FS : return new list element wifirst(L) = P;
last(L) = P;th 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;
}
Expand All @@ -31,7 +35,7 @@ void deallocate(address &P) {
* FS : delete element pointed by P
*/
//-------------your code here-------------
your code here
delete P;


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

Expand All @@ -55,9 +64,9 @@ void insertLast(List &L, address P) {
* 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;
//----------------------------------------
}

Expand All @@ -70,8 +79,10 @@ 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,7 +94,16 @@ 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 if (first(L) != NULL){
P = first(L);
first(L) = next(P);
next(P) = NULL;
prev(first(L)) = NULL;
}



Expand All @@ -96,21 +116,35 @@ 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 if (first(L) == last(L)){
P = first(L);
first(L) = NULL;
last(L) = NULL;
}



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

void printInfo(List L) {
/**
/**first(L) = P;
last(L) = P;
* 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 @@ -123,7 +157,16 @@ 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 (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);
}

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

Expand All @@ -135,9 +178,17 @@ 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 (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);
}
//----------------------------------------
}

16 changes: 9 additions & 7 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 All @@ -61,7 +63,7 @@ void insertLast(List &L, address P);
void deleteFirst(List &L, address &P);
void deleteLast(List &L, address &P);
void insertAfter(List &L, address Prec, address P);
void deleteAfter(List&L, address Prec, address &P);
void deleteAfter(List &L, address Prec, address &P);

// define search-by-ID function and view procedure
address findElm(List L, infotype x);
Expand Down
43 changes: 42 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,48 @@ void mainMenu() {
case 1:
X = create_data();
P = allocate(X);
insertFirst(L,P)
insertFirst(L,P);
break;
case 2:
printInfo(L);
break;
case 3:
cout << "Masukkan ID yang ingin dicari : ";
cin >> X.ID;
P = findElm(L, X);
if (P != NULL) {
view_data(info(P));
} else {
cout << "DATA TIDAK DITEMUKAN!\n";
}
break;
case 4:
cout << "Masukkan ID yang ingin diedit : ";
cin >> X.ID;
P = findElm(L, X);
if (P != NULL) {
edit_data(info(P));
} else {
cout << "DATA TIDAK DITEMUKAN!\n";
}
break;
case 5:
cout << "Masukkan ID yang ingin didelete : ";
cin >> X.ID;
if (findElm(L, X) != NULL) {
deletebyID(L, X.ID);
} else {
cout << "DATA TIDAK DITEMUKAN" << endl;
}
break;
case 6:
savePassedMember(L, L_passed);
break;
case 7:
printInfo(L_passed);
break;
}
if (choice == 0) {
break;
}
} while(true);
Expand Down
31 changes: 12 additions & 19 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 : Mohammad Mirza Qusyairi
STUDENT ID : 1301194203
**/

mytype create_data() {
Expand All @@ -15,11 +15,10 @@ mytype create_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 @@ -32,11 +31,7 @@ void view_data(mytype d) {

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




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

Expand All @@ -50,11 +45,9 @@ void edit_data(mytype &d) {

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




cout<<"Input ganti nama : "; cin>>d.name;
cout<<"Input ganti rank : "; cin>>d.rank;
cout<<"Input ganti score : "; cin>>d.score;
// ===========================
}

Loading