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

Muhammad Sulthon Asramanggala || 1301194008 || IF-43-05 #158

Open
wants to merge 2 commits 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
19 changes: 19 additions & 0 deletions ASD_Task_3.depend
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,22 @@
"operation.h"
"my_data.h"

1582381821 source:d:\github\latihan\asd_task_3\list.cpp
"list.h"
"my_data.h"

1582330300 d:\github\latihan\asd_task_3\list.h
<iostream>
"my_data.h"

1582381690 d:\github\latihan\asd_task_3\my_data.h
<iostream>

1582381876 source:d:\github\latihan\asd_task_3\operation.cpp
"list.h"
"operation.h"
"my_data.h"

1582327055 d:\github\latihan\asd_task_3\operation.h
"list.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="my_data.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="496" topLine="7" />
<Cursor1 position="821" topLine="13" />
</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="operation.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="288" topLine="0" />
<Cursor1 position="2769" topLine="83" />
</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="main.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2862" topLine="116" />
<Cursor1 position="1377" topLine="34" />
</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="my_data.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1006" topLine="0" />
<Cursor1 position="1538" topLine="62" />
</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="list.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="774" topLine="0" />
<Cursor1 position="4824" topLine="185" />
</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="list.h" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="688" topLine="17" />
<Cursor1 position="784" topLine="22" />
</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="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="207" topLine="0" />
</Cursor>
Expand Down
91 changes: 79 additions & 12 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ 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,8 +19,10 @@ address allocate(infotype x) {

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

P = new elmlist;
info(P) = x;
next(P) = NULL;

//----------------------------------------
return P;
Expand All @@ -31,20 +33,27 @@ 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);
first(L) = P;
}
else{
first(L) = P;
}

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

//----------------------------------------
}
Expand All @@ -67,11 +85,22 @@ 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;
}
}

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


//----------------------------------------
Expand All @@ -96,8 +132,17 @@ 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 = first(L);
if(first(L) != NULL){
while(next(next(P)) != NULL){
P = next(P);
}
next(P) = NULL;
}
else{
first(L) = NULL;
}


//----------------------------------------
Expand All @@ -109,8 +154,20 @@ 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;
if(first(L) != NULL){
P = first(L);
while(P != NULL){
cout<< "------------------------"<<endl;
view_data(info(P));
cout<< "------------------------"<<endl;
P = next(P);
}
}
else{
cout<<"kosong bro"<<endl;
}

//----------------------------------------
}
Expand All @@ -123,8 +180,15 @@ 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,8 +199,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);
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
85 changes: 73 additions & 12 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,72 @@ void mainMenu() {
cout<<"0. exit"<<endl;
cout<<"input choice: ";
cin>>choice;
switch(choice) {
case 1:
X = create_data();
P = allocate(X);
insertFirst(L,P)
break;
}
} while(true);
P = allocate(X);
insertFirst(L,P)
break;

//----------------------------------------
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 << "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);
//----------------------------------------
}
Loading