Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naufal Rezky Ananda - 1301190478 - IF-43-05 #148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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>

1583390485 source:d:\kuliah\semester 2\asd_task_4\player.cpp
"player.h"
<ctime>

1582637257 d:\kuliah\semester 2\asd_task_4\player.h
"list.h"

1582637384 d:\kuliah\semester 2\asd_task_4\list.h
<string>
<windows.h>
<iostream>

1583390998 source:d:\kuliah\semester 2\asd_task_4\list.cpp
"list.h"

1583391176 source:d:\kuliah\semester 2\asd_task_4\main.cpp
"player.h"
"list.h"
<conio.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="404" topLine="22" />
</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="list.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="342" topLine="0" />
<Cursor1 position="2744" topLine="105" />
</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="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2436" topLine="0" />
<Cursor1 position="5899" topLine="159" />
</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="player.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="253" topLine="39" />
<Cursor1 position="2997" topLine="74" />
</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="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="270" topLine="0" />
<Cursor1 position="170" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file added bin/Debug/ASD_Task_4.exe
Binary file not shown.
104 changes: 88 additions & 16 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,9 +15,11 @@ address allocate(infotype x) {
* next dan prev elemen = Nil
*/

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

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

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

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

Expand All @@ -47,7 +62,19 @@ void insertLast(List &L, address P) {
* FS : elemen yang ditunjuk P menjadi elemen terakhir 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;
}
else
{
first(L)=P;
next(first(L)) = P;
prev(first(L)) = P;
}
//----------------------------------------
}

Expand All @@ -58,11 +85,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 +104,18 @@ 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 +124,18 @@ 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(first(L))!=P){
first(L) = next(P);
next(prev(P)) = first(L);
prev(first(L)) = prev(P);
next(P) = NULL;
prev(P) = NULL;
}else{
next(P)=NULL;
prev(P)=NULL;
first(L)=NULL;
}
//----------------------------------------
}

Expand All @@ -95,8 +145,12 @@ 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(prev(P));
next(P) = NULL;
prev(P) = NULL;
//---------------------
}

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

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

}
Expand All @@ -117,6 +178,17 @@ void deleteAfter(List &L, address &Prec, address &P) {
* dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------
P = next(Prec);
if(next(Prec)!=first(L)){
next(Prec) = next(P);
prev(next(P)) = Prec;
next(P) = NULL;
prev(P) = NULL;
}else{
next(P)=NULL;
prev(P)=NULL;
P=NULL;
}

//----------------------------------------
}
Expand Down
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
43 changes: 36 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,17 @@ void runMenu(int menu) {
// insert first music
P = inputMusic();
insertFirst(L,P);
cout<<"press enter";getche();
cout<<"press enter";
getche();
break;
case 2:
// insert last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;
//input music
P=inputMusic();
insertLast(L,P);
cout << "press enter";
getche();
//insertLast()

//----------------------------------------
Expand All @@ -138,12 +142,17 @@ void runMenu(int menu) {
// play first music
P = first(L);
playMusic(P);
cout << "press enter";
getche();
break;
case 5:
// 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 @@ -154,15 +163,25 @@ void runMenu(int menu) {
P = findElmByName(L, x);
if(P != NULL){
cout<<"music found"<<endl;
}else{
cout<<"music not found"<<endl;
}
cout << "press enter";
getche();
//----------------------------------------
cout<<"press enter";getche();
break;
case 7:
// search music by ID
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

cin>>x.ID;
P = findElmByID(L, x);
if(P != NULL){
cout<<"music found"<<endl;
}else{
cout<<"music not found"<<endl;
}
//----------------------------------------
cout<<"press enter";getche();
break;
Expand All @@ -171,25 +190,35 @@ void runMenu(int menu) {
if(P!=NULL) {
playMusic(P);
}
cout << "press enter";
getche();
break;
case 9:
// play next music
if(P!=NULL) {
P = next(P);
playMusic(P);
}
cout << "press enter";
getche();
break;
case 10:
// 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:
// shuffle list
shuffleList(L);
cout<<"press enter";getche();
cout << "press enter";
getche();
break;
case 12:
// play repeat all music
Expand All @@ -202,7 +231,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