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
3 changes: 3 additions & 0 deletions ASD_Task_4.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Linker>
<Add library="winmm" />
</Linker>
<Unit filename="list.cpp" />
<Unit filename="list.h" />
<Unit filename="main.cpp" />
Expand Down
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>

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

1583490921 c:\users\asus\documents\github\asd_task_4\player.h
"list.h"

1583590871 c:\users\asus\documents\github\asd_task_4\list.h
<string>
<windows.h>
<iostream>

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

1583581414 source:c:\users\asus\documents\github\asd_task_4\list.cpp
"list.h"

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="1277" topLine="11" />
</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="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
<Cursor>
<Cursor1 position="342" topLine="0" />
<Cursor1 position="4763" topLine="111" />
</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.cpp" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2436" topLine="0" />
<Cursor1 position="1996" topLine="59" />
</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="list.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="253" topLine="39" />
<Cursor1 position="4501" topLine="158" />
</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="player.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="270" topLine="0" />
<Cursor1 position="342" topLine="7" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file added bin/Debug/ASD_Task_4.exe
Binary file not shown.
118 changes: 85 additions & 33 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ void createList(List &L) {
/**
* FS : first(L) diset Nil
*/
//------------- YOUR CODE HERE -------------

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

address allocate(infotype x) {
Expand All @@ -16,39 +14,51 @@ address allocate(infotype x) {
*/

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

//----------------------------------------
P= new elmlist;
info(P)=x;
next(P)=NULL;
prev(P)=NULL;
return P;
}

void deallocate(address &P) {
/**
* FS : menghapus elemen yang ditunjuk oleh P (delete)
*/
//------------- YOUR CODE HERE -------------

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

void insertFirst(List &L, address P) {
/**
* IS : List L mungkin kosong
* 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;
}
}

void insertLast(List &L, address P) {
/**
* IS : List L mungkin kosong
* 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;
}
}

address findElmByID(List L, infotype x) {
Expand All @@ -59,9 +69,13 @@ 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){
return NULL;
}
return P;
}

Expand All @@ -73,9 +87,13 @@ address findElmByName(List L, infotype x) {
*/

address P = NULL;
//------------- 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){
return NULL;
}
return P;
}

Expand All @@ -84,19 +102,44 @@ void deleteFirst(List &L, address &P) {
* IS : List L mungkin kosong
* 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;
}else if (prev(first(L))==next(first(L))){
first(L)=next(P);
next(first(L))=first(L);
prev(first(L))=first(L);
next(P)=NULL;
prev(P)=NULL;
}else{
first(L)=next(P);
next(prev(P))=first(L);
prev(first(L))=prev(P);
next(P)=NULL;
prev(P)=NULL;
}
}

void deleteLast(List &L, address &P) {
/**
* IS : List L mungkin kosong
* 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 if(prev(first(L))==next(first(L))){
next(first(L))=first(L);
prev(first(L))=first(L);
next(P)=NULL;
prev(P)=NULL;
}else{
next(prev(P))=first(L);
prev(first(L))=prev(P);
next(P)=NULL;
prev(P)=NULL;
}
}

void insertAfter(List &L, address &Prec, address P) {
Expand All @@ -105,9 +148,10 @@ void insertAfter(List &L, address &Prec, address P) {
* 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) {
Expand All @@ -116,8 +160,16 @@ void deleteAfter(List &L, address &Prec, address &P) {
* FS : elemen yang berada di belakang elemen Prec dilepas
* dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

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

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

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


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

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


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


Expand Down
40 changes: 19 additions & 21 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,8 @@ void runMenu(int menu) {
break;
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;
case 3:
Expand All @@ -141,29 +137,31 @@ void runMenu(int menu) {
break;
case 5:
// play last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

//----------------------------------------
P=prev(first(L));
playMusic(P);
break;
case 6:
// search music by name
//------------- YOUR CODE HERE -------------
cout<<"input music filename (.wav) : ";
cin>>x.name;
P = findElmByName(L, x);
if(P != NULL){
cout<<"music found"<<endl;
}else{
cout<<"music not found";
}
//----------------------------------------
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";
}
cout<<"press enter";getche();
break;
case 8:
Expand All @@ -181,10 +179,10 @@ void runMenu(int menu) {
break;
case 10:
// play previous music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

//----------------------------------------
if (P!=NULL){
P=prev(P);
playMusic(P);
}
break;
case 11:
// shuffle list
Expand All @@ -202,7 +200,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