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

1583570365 source:d:\strukdat\asd_task_4\list.cpp
"list.h"

1583570365 d:\strukdat\asd_task_4\list.h
<string>
<windows.h>
<iostream>

1583570365 source:d:\strukdat\asd_task_4\player.cpp
"player.h"
<ctime>

1583570365 d:\strukdat\asd_task_4\player.h
"list.h"

Binary file added bin/Debug/ASD_Task_4.exe
Binary file not shown.
114 changes: 99 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 @@ -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,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(first(L)) = P;
prev(first(L)) = 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{
if(info(P).ID == x.ID){
return P;
}
P = next(P);
}while(P != first(L) && first(L) != NULL);
//----------------------------------------
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 {
if(info(P).name == x.name){
return P;
}
P = next(P);
}while(P != first(L));
//----------------------------------------
return P;
return NULL;
}

void deleteFirst(List &L, address &P) {
Expand All @@ -85,7 +117,19 @@ void deleteFirst(List &L, address &P) {
* FS : elemen pertama di dalam List L dilepas dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

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

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

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

Expand All @@ -106,7 +159,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 +173,35 @@ 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;
}
//----------------------------------------
}

void insertAndShort(List &L, infotype x){
address P,Q ;
P = first(L) ;
if ((P == NULL) || (info(P).ID > x.ID))
{
insertFirst(L,allocate(x)) ;
}
else if (findElmByID(L,x) == NULL)
{
while ((P != NULL) && (info(P).ID < x.ID))
{
Q = P ;
P = next(P) ;
}
insertAfter(L,Q,allocate(x));
}
}
10 changes: 5 additions & 5 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 All @@ -61,5 +61,5 @@ void deleteAfter(List &, address &, address &);
address findElmByID(List, infotype );
address findElmByName(List, infotype );


void insertAndShort(List &L, infotype x);
#endif // LIST_H_INCLUDED
37 changes: 27 additions & 10 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,9 @@ 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 @@ -136,7 +135,7 @@ void runMenu(int menu) {
break;
case 4:
// play first music
P = first(L);
P = prev(first(L));
playMusic(P);
break;
case 5:
Expand All @@ -153,16 +152,32 @@ void runMenu(int menu) {
cin>>x.name;
P = findElmByName(L, x);
if(P != NULL){
cout<<"music found"<<endl;
cout<<"--Music Found--"<<endl;
cout<<endl;
cout<<"Name Music : "<<info(P).name<<endl;
cout<<"ID Music : "<<info(P).ID<<endl;
cout<<"Location Music: "<<info(P).location<<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;
cout<<endl;
cout<<"Name Music : "<<info(P).name<<endl;
cout<<"ID Music : "<<info(P).ID<<endl;
cout<<"Location Music: "<<info(P).location<<endl;
}else{
cout<<"Music Not Found"<<endl;
}
//----------------------------------------
cout<<"press enter";getche();
break;
Expand All @@ -182,8 +197,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 +219,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.
46 changes: 37 additions & 9 deletions player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,25 @@ void shuffleList(List &L) {
* FS : isi (elemen) dari list teracak
*/
//------------- YOUR CODE HERE -------------

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

address P = first(L);
int i = 0;
do{
P = next(P);
i++;
}while (P != first(L));

address Q,R;
for(int j = 1; j <= i; j++){
int hasilAcak = randomInt(j);
int h = 1;
Q = first(L);
do{
h++;
Q = next(Q);
}while (Q != first(L) && h < hasilAcak);
deleteAfter(L,prev(Q),R);
insertFirst(L,R);
}
//----------------------------------------
}

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

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

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

Expand All @@ -69,9 +89,17 @@ 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(P == NULL){
cout<<"Music Not Found"<<endl;
}else if (next(P) == first(L)){
deleteFirst(L,P);
deallocate(P);
}else if(info(next(P)).ID == x.ID){
deleteAfter(L,P,Q);
}
//----------------------------------------

}