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>

1583422943 source:c:\latihan coding\asd_task_4\list.cpp
"list.h"

1582973393 c:\latihan coding\asd_task_4\list.h
<string>
<windows.h>
<iostream>

1583422826 source:c:\latihan coding\asd_task_4\main.cpp
"player.h"
"list.h"
<conio.h>

1582871284 c:\latihan coding\asd_task_4\player.h
"list.h"

1583421257 source:c:\latihan coding\asd_task_4\player.cpp
"player.h"
<ctime>

20 changes: 10 additions & 10 deletions ASD_Task_4.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="list.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4763" topLine="177" />
<Cursor1 position="233" topLine="44" />
</Cursor>
</File>
<File name="player.h" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="player.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="342" topLine="0" />
<Cursor1 position="1224" topLine="37" />
</Cursor>
</File>
<File name="list.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="player.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2436" topLine="0" />
<Cursor1 position="342" topLine="8" />
</Cursor>
</File>
<File name="player.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="253" topLine="39" />
<Cursor1 position="5026" topLine="18" />
</Cursor>
</File>
<File name="list.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="list.cpp" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0">
<Cursor>
<Cursor1 position="270" topLine="0" />
<Cursor1 position="3724" topLine="129" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file added asset/baka.wav
Binary file not shown.
Binary file added asset/explosioon.wav
Binary file not shown.
Binary file added asset/unyo.m4a
Binary file not shown.
Binary file added bin/Debug/ASD_Task_4.exe
Binary file not shown.
102 changes: 85 additions & 17 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) = NIL;
//----------------------------------------
}

Expand All @@ -15,9 +15,12 @@ address allocate(infotype x) {
* next dan prev elemen = Nil
*/

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

P = new elmlist;
info(P) = x;
next(P) = NIL;
prev(P) = NIL;
//----------------------------------------
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,18 @@ void insertFirst(List &L, address P) {
* FS : elemen yang ditunjuk P menjadi elemen pertama pada List L
*/
//------------- YOUR CODE HERE -------------

if(first(L) == NIL){
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 +61,15 @@ void insertLast(List &L, address P) {
* FS : elemen yang ditunjuk P menjadi elemen terakhir pada List L
*/
//------------- YOUR CODE HERE -------------

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

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

address P = NULL;
address P = NIL;
//------------- 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 = NIL;
}
//----------------------------------------
return P;
}
Expand All @@ -72,9 +100,15 @@ address findElmByName(List L, infotype x) {
mengembalikan Nil jika tidak ditemukan
*/

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

P = first(L);
do{
P = next(P);
} while(P!= first(L) && info(P).name != x.name);
if(P == first(L) && info(P).name != x.name){
P = NIL;
}
//----------------------------------------
return P;
}
Expand All @@ -85,7 +119,21 @@ 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) = NIL ;
next(P) = NIL;
prev(P) = NIL;
}
else
{
first(L) = next(first(L));
next(prev(P)) = first(L);
prev(first(L)) = prev(P);
next(P) = NIL;
prev(P) = NIL;
}
//----------------------------------------
}

Expand All @@ -95,29 +143,49 @@ 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));
next(prev(P)) = first(L);
prev(first(L)) = prev(P);
next(P) = NIL;
prev(P) = NIL;
//----------------------------------------
}

void insertAfter(List &L, address &Prec, address P) {
/**
* IS : Prec dan P tidak NULL
* IS : Prec dan P tidak NIL
* FS : elemen yang ditunjuk P menjadi elemen di belakang elemen yang
* ditunjuk pointer Prec
*/
//------------- YOUR CODE HERE -------------

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

}
void deleteAfter(List &L, address &Prec, address &P) {
/**
* IS : Prec tidak NULL
* IS : Prec tidak NIL
* FS : elemen yang berada di belakang elemen Prec dilepas
* dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

P = next(Prec) ;
if (next(Prec) == Prec)
{
next(P) = NIL ;
prev(P) = NIL ;
next(Prec) = Prec ;
prev(Prec) = Prec ;
}
else
{
next(Prec) = next(P) ;
prev(next(P)) = Prec ;
next(P) = NIL ;
prev(P) = NIL ;
}
//----------------------------------------
}

10 changes: 6 additions & 4 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define next(P) P->next
#define prev(P) P->prev
#define info(P) P->info
#define NIL NULL

using namespace std;

Expand All @@ -29,15 +30,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 +62,6 @@ void deleteAfter(List &, address &, address &);
address findElmByID(List, infotype );
address findElmByName(List, infotype );

void insertAndSort(List &, infotype );

#endif // LIST_H_INCLUDED
46 changes: 30 additions & 16 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 @@ -137,13 +135,21 @@ void runMenu(int menu) {
case 4:
// play first music
P = first(L);
playMusic(P);
if(P!=NIL){
playMusic(P);
} else {
cout<<"List Kosong"<<endl;
}
break;
case 5:
// play last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

P = prev(first(L));
if(P!=NIL){
playMusic(P);
} else {
cout<<"List Kosong"<<endl;
}
//----------------------------------------
break;
case 6:
Expand All @@ -152,44 +158,52 @@ void runMenu(int menu) {
cout<<"input music filename (.wav) : ";
cin>>x.name;
P = findElmByName(L, x);
if(P != NULL){
if(P != NIL){
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 != NIL){
cout<<"music found"<<endl;
} else {
cout<<"music not found"<<endl;
}
//----------------------------------------
cout<<"press enter";getche();
break;
case 8:
// play current music
if(P!=NULL) {
if(P!=NIL) /**antisipasi list kosong*/{
playMusic(P);
}
break;
case 9:
// play next music
if(P!=NULL) {
if(P!=NIL)/**antisipasi list kosong*/ {
P = next(P);
playMusic(P);
}
break;
case 10:
// play previous music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

P = prev(P);
playMusic(P);
//----------------------------------------
break;
case 11:
// shuffle list
shuffleList(L);
cout<<"press enter";getche();
cout<<"music has been shuffle"<<endl<<"press enter";getche();
break;
case 12:
// play repeat all music
Expand All @@ -202,7 +216,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.
Loading