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"

1582378378 source:c:\users\user\documents\github\asd_task_3\list.cpp
"list.h"
"my_data.h"

1582378473 c:\users\user\documents\github\asd_task_3\list.h
<iostream>
"my_data.h"

1582378977 c:\users\user\documents\github\asd_task_3\my_data.h
<iostream>

1582378925 source:c:\users\user\documents\github\asd_task_3\my_data.cpp
"my_data.h"

1582379110 source:c:\users\user\documents\github\asd_task_3\operation.cpp
"list.h"
"operation.h"
"my_data.h"

1582377757 c:\users\user\documents\github\asd_task_3\operation.h
"list.h"

1582379413 source:c:\users\user\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: 71 additions & 30 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ 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 +20,8 @@ address allocate(infotype x) {

address P;
//-------------your code here-------------
your code here


P = new elmlist;
info(P) = x;
//----------------------------------------
return P;
}
Expand All @@ -31,9 +31,7 @@ void deallocate(address &P) {
* FS : delete element pointed by P
*/
//-------------your code here-------------
your code here


delete P;
//----------------------------------------
}

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

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

Expand All @@ -70,8 +83,11 @@ address findElm(List L, infotype x) {

address P;
//-------------your code here-------------
your code here

P = first(L);
while ((P != NULL) && (x.ID != info(P).ID))
{
P = next(P);
}

//----------------------------------------
return P;
Expand All @@ -83,9 +99,18 @@ 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


P = first(L);
if (first(L) != NULL)
{
first(L) = next(P);
next(P) = NULL;
prev(first(L)) = NULL;
}
else if (first(L) == last(L))
{
first(L) = NULL;
last(L) = NULL;
}

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

Expand All @@ -109,9 +143,14 @@ 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;
P = first(L);
while (P != NULL)
{
view_data(info(P));
P = next(P);
}
cout << endl;
//----------------------------------------
}

Expand All @@ -123,8 +162,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,9 +176,9 @@ 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);
next(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 prev;
address next;
//----------------------------------------
};

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


address first;
address last;
//----------------------------------------
};

Expand Down
47 changes: 43 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ void mainMenu() {
* 0. exit
*/
//-------------your code here-------------
int choice;
do {
int choice;
do {
cout<<"Menu"<<endl;
cout<<"1. insert"<<endl;
cout<<"2. view member"<<endl;
Expand All @@ -51,10 +51,49 @@ 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: ";
cin>>X.ID;
P = findElm(L, X);
if (P!=NULL){
view_data(info(P));
}else{
cout<<"Not Found\n";
}
break;
case 4:
cout<<"Masukkan ID: ";
cin>>X.ID;
P = findElm(L, X);
if (P!=NULL){
edit_data(info(P));
}else{
cout<<"Not Found\n";
}
break;
case 5:
cout << "Masukkan 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:
cout<<"hehe";
printInfo(L_passed);
break;

}
} while(true);

//----------------------------------------
}
32 changes: 16 additions & 16 deletions my_data.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#include "my_data.h"

/**
Expand All @@ -15,11 +15,14 @@ mytype create_data() {
mytype d;
// ===========================
// YOUR CODE HERE
your code here




cout<<"Masukan ID: ";
cin>>d.ID;
cout<<"Masukan Nama: ";
cin>>d.name;
cout<<"Masukan ranking : ";
cin>>d.rank;
cout<<"Masukan score : ";
cin>>d.score;
// ===========================
return d;
}
Expand All @@ -32,11 +35,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 +49,12 @@ void edit_data(mytype &d) {

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




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

8 changes: 5 additions & 3 deletions my_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ struct mytype {
*/
//=================================================
// YOUR CODE STARTS HERE
your code here

int ID;
string name;
int rank;
float score;
// YOUR CODE ENDS HERE
//=================================================
};


mytype create_data();
void view_data(mytype d);
void edit_data(mytype &d);
void edit_data(mytype &d);

#endif // MY_DATA_H_INCLUDED
Binary file added obj/Debug/list.o
Binary file not shown.
Binary file added obj/Debug/main.o
Binary file not shown.
Binary file added obj/Debug/my_data.o
Binary file not shown.
Binary file added obj/Debug/operation.o
Binary file not shown.
Loading