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>

1583592724 source:d:\std\github\asd_task_4\list.cpp
"list.h"

1583514475 d:\std\github\asd_task_4\list.h
<string>
<windows.h>
<iostream>

1583522349 source:d:\std\github\asd_task_4\player.cpp
"player.h"
<ctime>

1582640754 d:\std\github\asd_task_4\player.h
"list.h"

1583592461 source:d:\std\github\asd_task_4\main.cpp
"player.h"
"list.h"
<conio.h>

Binary file added bin/Debug/ASD_Task_4.exe
Binary file not shown.
71 changes: 60 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,12 @@ address allocate(infotype x) {

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

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

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

Expand All @@ -37,7 +42,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){
next(P)=first(L);
prev(P)=prev(first(L));
next(prev(first(L)))=P;
prev(first(L))=P;
first(L)=P;
}else {
first(L)=P;
next(P)=P;
prev(P)=P;
}
//----------------------------------------
}

Expand All @@ -47,7 +62,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,7 +82,9 @@ address findElmByID(List L, infotype x) {

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

while(next(P)!=first(L) && info(P).ID!=x.ID){
P=next(P);
}
//----------------------------------------
return P;
}
Expand All @@ -74,7 +98,9 @@ address findElmByName(List L, infotype x) {

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

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

if(next(P)==first(L)){
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 +130,16 @@ void deleteLast(List &L, address &P) {
* FS : elemen tarakhir di dalam List L dilepas dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

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

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

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

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

P=next(Prec);
next(Prec)=next(P);
next(prev(first(L)))=first(L);
//----------------------------------------
}

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
21 changes: 14 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ void runMenu(int menu) {
case 2:
// insert last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;
P=inputMusic();
insertLast(L,P);
//input music
//insertLast()

Expand All @@ -142,8 +143,10 @@ void runMenu(int menu) {
case 5:
// play last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

P=prev(first(L));
if(P!=NULL){
playMusic(P);
}
//----------------------------------------
break;
case 6:
Expand All @@ -161,8 +164,12 @@ void runMenu(int menu) {
case 7:
// search music by ID
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

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

P=prev(P);
playMusic(P);
//----------------------------------------
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.
39 changes: 36 additions & 3 deletions player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,25 @@ void shuffleList(List &L) {
* FS : isi (elemen) dari list teracak
*/
//------------- YOUR CODE HERE -------------

address P;
P=first(L);
int i=0;
int j=randomInt(i);
while (P!=first(L)) {
i++;
P=next(P);
}
while (i>0) {
P=first(L);
while (j!=0){
P=next(P);
j--;
}
address Prec=P;
deleteAfter(L, prev(P), Prec);
insertFirst(L, Prec);
i--;
}
cout<<"UNDER MAIN TENIS"<<endl;

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

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

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

address P;
if (first(L)!=NULL) {
if (findElmByID(L, x) != NULL){
deleteAfter(L, prev(findElmByID(L, x)), P);
deallocate(P);
}
}
cout<<"UNDER MAIN TENIS"<<endl;

//----------------------------------------
Expand Down