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

WAHYU HAUZAN RAFI | 1301191313 | IF-43-05 #154

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
20 changes: 20 additions & 0 deletions ASD_Task_4.depend
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,23 @@
"player.h"
<ctime>

1583562406 source:c:\users\user\documents\github\asd_task_4\main.cpp
"player.h"
"list.h"
<conio.h>

1583335737 c:\users\user\documents\github\asd_task_4\player.h
"list.h"

1583556155 c:\users\user\documents\github\asd_task_4\list.h
<string>
<windows.h>
<iostream>

1583562315 source:c:\users\user\documents\github\asd_task_4\player.cpp
"player.h"
<ctime>

1583561542 source:c:\users\user\documents\github\asd_task_4\list.cpp
"list.h"

Binary file added bin/Debug/ASD_Task_4.exe
Binary file not shown.
86 changes: 75 additions & 11 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ void createList(List &L) {
* FS : first(L) diset Nil
*/
//------------- YOUR CODE HERE -------------

first(L) = NULL;
//----------------------------------------
}

Expand All @@ -17,7 +17,10 @@ address allocate(infotype x) {

address P = NULL;
//------------- YOUR CODE HERE -------------

P = new elmlist;
info(P) = x;
next(P) = NULL;
prev(P) = NULL;
//----------------------------------------
return P;
}
Expand All @@ -27,7 +30,7 @@ void deallocate(address &P) {
* FS : menghapus elemen yang ditunjuk oleh P (delete)
*/
//------------- YOUR CODE HERE -------------

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

Expand All @@ -37,7 +40,17 @@ void insertFirst(List &L, address P) {
* FS : elemen yang ditunjuk P menjadi elemen pertama pada List L
*/
//------------- YOUR CODE HERE -------------

if(first(L) == NULL){
first(L) = P;
next(P) = P;
prev(P) = P;
} else {
next(P) = first(L);
prev(P) = prev(first(L));
next(prev(first(L))) = P;
prev(first(L)) = P;
first(L) = P;
}
//----------------------------------------
}

Expand All @@ -47,7 +60,14 @@ void insertLast(List &L, address P) {
* FS : elemen yang ditunjuk P menjadi elemen terakhir pada List L
*/
//------------- YOUR CODE HERE -------------

if(first(L) == NULL){
insertFirst(L, P);
} else {
next(P) = first(L);
prev(P) = prev(first(L));
next(prev(first(L))) = P;
prev(first(L)) = P;
}
//----------------------------------------
}

Expand All @@ -60,8 +80,14 @@ address findElmByID(List L, infotype x) {

address P = NULL;
//------------- YOUR CODE HERE -------------

P = first(L);
do{
P = next(P);
}while(P != first(L) && info(P).ID != x.ID);
//----------------------------------------
if(P == first(L) && info(P).ID != x.ID){
P = NULL;
}
return P;
}

Expand All @@ -74,7 +100,14 @@ address findElmByName(List L, infotype x) {

address P = NULL;
//------------- YOUR CODE HERE -------------

P = first(L);
do{
P = next(P);
}while(info(P).name != x.name && P != first(L));
//----------------------------------------
if(info(P).name != x.name && P == first(L)){
P = NULL;
}
//----------------------------------------
return P;
}
Expand All @@ -85,7 +118,16 @@ void deleteFirst(List &L, address &P) {
* FS : elemen pertama di dalam List L dilepas dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

P = first(L);
if(next(P) == first(L)){
next(P) = NULL;
prev(P) = NULL;
first(L) = NULL;
} else {
next(prev(first(L))) = next(P);
first(L) = next(P);
next(prev(first(L))) = first(L);
}
//----------------------------------------
}

Expand All @@ -95,7 +137,13 @@ void deleteLast(List &L, address &P) {
* FS : elemen tarakhir di dalam List L dilepas dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

P = prev(first(L));
if(P == first(L)){
deleteFirst(L, P);
} else {
prev(first(L)) = prev(P);
next(prev(P)) = first(L);
}
//----------------------------------------
}

Expand All @@ -106,7 +154,10 @@ void insertAfter(List &L, address &Prec, address P) {
* ditunjuk pointer Prec
*/
//------------- YOUR CODE HERE -------------

next(P) = next(Prec);
prev(P) = Prec;
prev(next(Prec)) = P;
next(Prec) = P;
//----------------------------------------

}
Expand All @@ -117,7 +168,20 @@ void deleteAfter(List &L, address &Prec, address &P) {
* dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

P = next(Prec);
if(next(Prec) == first(L)){
deleteLast(L, P);
} else if (next(Prec) == Prec){
next(P) = NULL;
prev(P) = NULL;
next(Prec) = Prec;
prev(Prec) = Prec;
} else {
next(Prec) = next(P);
prev(next(P)) = Prec;
next(P) = NULL;
prev(P) = NULL;
}
//----------------------------------------
}

9 changes: 4 additions & 5 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ typedef struct elmlist *address;

struct elmlist {
//------------- YOUR CODE HERE -----------


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

struct List {
//------------- YOUR CODE HERE -----------


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



/** YOU DON'T NEED TO MODIFY THIS */

void createList(List &);
Expand Down
30 changes: 19 additions & 11 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ void runMenu(int menu) {
case 2:
// insert last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;
//input music
//insertLast()

P = inputMusic();
insertLast(L, P);
//----------------------------------------
cout<<"press enter";getche();
break;
Expand All @@ -142,8 +140,8 @@ void runMenu(int menu) {
case 5:
// play last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

P = prev(first(L));
playMusic(P);
//----------------------------------------
break;
case 6:
Expand All @@ -154,15 +152,23 @@ void runMenu(int menu) {
P = findElmByName(L, x);
if(P != NULL){
cout<<"music found"<<endl;
} else {
cout<<"music not found"<<endl;
}
//----------------------------------------
cout<<"press enter";getche();
break;
case 7:
// search music by ID
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

cout<<"input music ID : ";
cin>>x.ID;
P = findElmByID(L, x);
if(P != NULL){
cout<<"music found"<<endl;
} else {
cout<<"music not found"<<endl;
}
//----------------------------------------
cout<<"press enter";getche();
break;
Expand All @@ -182,8 +188,10 @@ void runMenu(int menu) {
case 10:
// play previous music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

if(P!=NULL) {
P = prev(P);
playMusic(P);
}
//----------------------------------------
break;
case 11:
Expand All @@ -202,7 +210,7 @@ void runMenu(int menu) {
case 13:
// delete music by ID
cout<<"input music ID : ";
cin>>x.name;
cin>>x.ID;
deleteMusicByID(L, x);
cout<<"press enter";getche();
break;
Expand Down
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/player.o
Binary file not shown.
54 changes: 43 additions & 11 deletions player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ void printInfo(List L) {
*/

address Q = first(L);
do {
if(first(L) != NULL){
do {
cout<<"name : "<<info(Q).name<<endl
<<"ID : "<<info(Q).ID<<endl
<<"location: "<<info(Q).location<<endl;
Q = next(Q);
} while(Q!=first(L));
} while(Q != first(L) && first(L) != NULL);
} else {
cout<<"Tidak Ada Lagu"<<endl;
}
cout<<"==============================================="<<endl;
}

Expand All @@ -43,9 +47,24 @@ void shuffleList(List &L) {
* FS : isi (elemen) dari list teracak
*/
//------------- YOUR CODE HERE -------------

cout<<"UNDER MAIN TENIS"<<endl;

address P = first(L);
address Q;
int lenList = 0;
do{
lenList = lenList + 1;
P = next(P);
} while(P != first(L));
while(lenList > 0){
P = first(L);
int random = randomInt(lenList);
while(random != 0){
P = next(P);
random = random - 1;
}
deleteAfter(L, prev(P), Q);
insertFirst(L, Q);
lenList = lenList - 1;
}
//----------------------------------------
}

Expand All @@ -55,9 +74,16 @@ void playRepeat(List &L, int n) {
* dari lagu pertama hingga terakhir sebanyak n kali
*/
//------------- YOUR CODE HERE -------------

cout<<"UNDER MAIN TENIS"<<endl;

address P = first(L);
int i = 1;
while(i <= n){
do{
cout<<"Sedang memutar lagu: "<<info(P).name<<endl;
playMusic(P);
P = next(P);
}while(P != first(L));
i = i + 1;
}
//----------------------------------------
}

Expand All @@ -69,9 +95,15 @@ void deleteMusicByID(List &L, infotype x) {
* FS : elemen dengan ID yang dicari dideallocate
*/
//------------- YOUR CODE HERE -------------

cout<<"UNDER MAIN TENIS"<<endl;

address P, Q;
P = findElmByID(L, x);
P = prev(P);
if(next(P) == first(L)){
deleteFirst(L, P);
} else if(info(next(P)).ID == x.ID){
deleteAfter(L, P, Q);
deallocate(Q);
}
//----------------------------------------

}