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"

1582029680 source:c:\users\rulz\documents\github\asd_task_3\my_data.cpp
"my_data.h"

1582029833 c:\users\rulz\documents\github\asd_task_3\my_data.h
<iostream>

1582030192 source:c:\users\rulz\documents\github\asd_task_3\list.cpp
"list.h"
"my_data.h"

1582028654 c:\users\rulz\documents\github\asd_task_3\list.h
<iostream>
"my_data.h"

1582030314 source:c:\users\rulz\documents\github\asd_task_3\operation.cpp
"list.h"
"operation.h"
"my_data.h"

1582028356 c:\users\rulz\documents\github\asd_task_3\operation.h
"list.h"

1582030322 source:c:\users\rulz\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.
110 changes: 96 additions & 14 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void createList(List &L) {
* FS : set first(L) and last(L) with Null
*/
//-------------your code here-------------
your code here
first(L) = NULL;


//----------------------------------------
Expand All @@ -19,7 +19,9 @@ address allocate(infotype x) {

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


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


//----------------------------------------
Expand All @@ -43,7 +45,12 @@ 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);
first(L) = P;
} else{
first(L) = P;
}


//----------------------------------------
Expand All @@ -55,7 +62,19 @@ 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){
address Q = first(L);
while ( next(Q)!= NULL)
{
Q=next(Q);
}
next(Q)=P;
}
else
{
insertFirst(L,P);
}



//----------------------------------------
Expand All @@ -67,10 +86,25 @@ address findElm(List L, infotype x) {
* FS : returns element with info.ID = x.ID,
return Null if such ID is not found
*/

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


//----------------------------------------
Expand All @@ -83,33 +117,69 @@ 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) != NULL){
P= first(L);
first(L)=next(P);
next(P)=NULL;
}
else
{
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
P = first(L);
if (first(L)!= NULL)
{
while (next(next(P)) != NULL){
P = next(P);
}
next(P)= NULL;
}
else
{
first(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;
if (first(L) != NULL)
{
P = first(L);
while (P != NULL)
{
cout << "======================================="<<endl;
view_data(info(P));
cout << "======================================="<<endl;
P = next(P);
}
}
else
{
cout<<"kosong"<<endl;
}


//----------------------------------------
Expand All @@ -123,7 +193,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
{
address Prec;
next(P)=next(Prec);
next(Prec)=P;
}

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

Expand All @@ -135,7 +214,10 @@ 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;
deallocate(P);


//----------------------------------------
Expand Down
11 changes: 6 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,14 @@ typedef struct elmlist *address;

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

infotype info;
address next;
//----------------------------------------
};

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

address first;

//----------------------------------------
};
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void mainMenu() {
case 1:
X = create_data();
P = allocate(X);
insertFirst(L,P)
insertFirst(L,P);
break;
}
} while(true);
Expand Down
37 changes: 30 additions & 7 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 : MUHAMMAD KHIYARUS SYIAM
STUDENT ID : 1301194242
**/

mytype create_data() {
Expand All @@ -15,7 +15,15 @@ mytype create_data() {
mytype d;
// ===========================
// YOUR CODE HERE
your code here
cout << "ID anda : ";
cin >> d.ID;
cout << "Nama anda : ";
cin >> d.name;
cout << "Rangking anda : ";
cin >> d.ranking;
cout << "Score anda : ";
cin >> d.score;




Expand All @@ -32,7 +40,10 @@ void view_data(mytype d) {

// ===========================
// YOUR CODE HERE
your code here
cout << "ID : " << d.ID << endl;
cout << "Nama : " << d.name << endl;
cout << "Rank : " << d.ranking << endl;
cout << "Score : " << d.score << endl;



Expand All @@ -50,7 +61,19 @@ void edit_data(mytype &d) {

// ===========================
// YOUR CODE HERE
your code here
cout <<"ID : "<< d.ID<<endl;
cout <<"Nama : "<< d.name<<endl;
cout <<"Rangking : "<< d.ranking<<endl;
cout <<"Score : "<< d.score<<endl;
cout << endl;
cout << "Masukkan Data Baru : "<<endl;
cout <<"ID anda: " << d.ID<<endl;
cout << "Nama Baru : ";
cin >> d.name;
cout << "Ranking Baru : ";
cin >> d.ranking;
cout << "Score Baru : ";
cin >> d.score;



Expand Down
13 changes: 8 additions & 5 deletions my_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using namespace std;

/**
CLASS :
NAME :
STUDENT ID :
CLASS : IF - 43 - 05
NAME : MUHAMMAD KHIYARUS SYIAM
STUDENT ID : 1301194242
**/

struct mytype {
Expand All @@ -20,7 +20,10 @@ struct mytype {
*/
//=================================================
// YOUR CODE STARTS HERE
your code here
int ID;
string name;
int ranking;
float score;

// YOUR CODE ENDS HERE
//=================================================
Expand All @@ -29,6 +32,6 @@ struct mytype {

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