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

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

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

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

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

1583592973 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.
89 changes: 74 additions & 15 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 @@ -15,8 +15,11 @@ address allocate(infotype x) {
* next dan prev elemen = Nil
*/

address P = NULL;
address P;
//------------- YOUR CODE HERE -------------
P = new elmlist;
info(P) = x;
next(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,16 @@ void insertLast(List &L, address P) {
* FS : elemen yang ditunjuk P menjadi elemen terakhir 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;
}
//----------------------------------------
}

Expand All @@ -58,11 +80,16 @@ address findElmByID(List L, infotype x) {
mengembalikan Nil jika tidak ditemukan
*/

address P = NULL;
address P = first(L);
//------------- YOUR CODE HERE -------------

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

address findElmByName(List L, infotype x) {
Expand All @@ -72,11 +99,16 @@ address findElmByName(List L, infotype x) {
mengembalikan Nil jika tidak ditemukan
*/

address P = NULL;
address P = first(L);
//------------- YOUR CODE HERE -------------

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

void deleteFirst(List &L, address &P) {
Expand All @@ -85,7 +117,14 @@ 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)){
first(L) = NULL;
}else{
next(prev(first(L))) = next(P);
first(L) = next(P);
next(prev(first(L))) = first(L);
}
//----------------------------------------
}

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

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

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

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

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

P = next(Prec);
if(next(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;
}
//----------------------------------------
}

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

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


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

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


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

Expand Down
23 changes: 18 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ void runMenu(int menu) {
// insert last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;
//input music
//insertLast()
P = inputMusic();
insertLast(L, P);
cout << "press enter";getche();

//----------------------------------------
cout<<"press enter";getche();
Expand All @@ -143,7 +144,9 @@ void runMenu(int menu) {
// play last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

P = prev(first(L));
playMusic(P);
cout << "press enter";getche();
//----------------------------------------
break;
case 6:
Expand All @@ -162,7 +165,13 @@ void runMenu(int menu) {
// search music by ID
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

cin >> x.ID;
P = findElmByID(L, x);
if(P != NULL){
cout << "Musik Ditemukan" << endl;
}else{
cout << "Musik Tidak Ditemukan" << endl;
}
//----------------------------------------
cout<<"press enter";getche();
break;
Expand All @@ -183,7 +192,11 @@ void runMenu(int menu) {
// play previous music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

if(P != NULL){
P = prev(P);
playMusic(P);
}
cout << "press enter";getche();
//----------------------------------------
break;
case 11:
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.
79 changes: 62 additions & 17 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 {
cout<<"name : "<<info(Q).name<<endl
<<"ID : "<<info(Q).ID<<endl
<<"location: "<<info(Q).location<<endl;
Q = next(Q);
} while(Q!=first(L));
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));
}else{
cout << "List Kosong" << endl;
}
cout<<"==============================================="<<endl;
}

Expand All @@ -29,11 +33,14 @@ void playMusic(address P) {
* PR : memainkan lagu yang ditunjuk oleh pointer P
* YOU DON'T NEED TO MODIFY THIS
*/

string filename = info(P).location+"/"+info(P).name;
cout<<"playing "<<filename<<endl;
PlaySound(TEXT(filename.c_str()), NULL, SND_FILENAME);
_sleep(500); //delay 0.5 second
if(P != NULL){
string filename = info(P).location+"/"+info(P).name;
cout<<"playing "<<filename<<endl;
PlaySound(TEXT(filename.c_str()), NULL, SND_FILENAME);
_sleep(500); //delay 0.5 second
}else{
cout << "Musik Tidak Ada" << endl;
}
}


Expand All @@ -44,8 +51,27 @@ void shuffleList(List &L) {
*/
//------------- YOUR CODE HERE -------------

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

cout<<"UNDER MAIN TENIS"<<endl;
address P = first(L);
int i = 0;
do{
P = next(P);
i++;
}while(P != first(L));
address Q;
address R;
int j;
for(j=1; j<=1; j++){
int acak = randomInt(j);
int k = 1;
Q = first(L);
do{
Q = next(Q);
k++;
}while(Q != first(L) && k < acak);
deleteAfter(L, prev(Q), R);
insertFirst(L, R);
}
//----------------------------------------
}

Expand All @@ -56,8 +82,15 @@ void playRepeat(List &L, int n) {
*/
//------------- YOUR CODE HERE -------------

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

cout<<"UNDER MAIN TENIS"<<endl;
int i;
for(i=0; i<n; i++){
address P = first(L);
do{
playMusic(P);
P = next(P);
}while(P != first(L));
}
//----------------------------------------
}

Expand All @@ -70,8 +103,20 @@ void deleteMusicByID(List &L, infotype x) {
*/
//------------- YOUR CODE HERE -------------

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

cout<<"UNDER MAIN TENIS"<<endl;
address R;
address cari = findElmByID(L, x);
if(cari == NULL){
cout << "Music Tidak Ditemukan" << endl;
}else if(cari == first(L)){
deleteFirst(L, R);
deallocate(R);
cout << "Delete Berhasil" << endl;
}else if(cari != NULL){
deleteAfter(L, prev(cari), R);
deallocate(R);
cout << "Delete Berhasil" << endl;
}
//----------------------------------------

}