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

PR FROM BERLIANA SAHAFA WARDANI | 1301194181 | IF-43-05 #163

Open
wants to merge 1 commit 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>

1583587627 source:d:\tugas kuliah\github\asd_task-4\asd_task_4\main.cpp
"player.h"
"list.h"
<conio.h>

1583496536 d:\tugas kuliah\github\asd_task-4\asd_task_4\player.h
"list.h"

1583587651 d:\tugas kuliah\github\asd_task-4\asd_task_4\list.h
<string>
<windows.h>
<iostream>

1583587775 source:d:\tugas kuliah\github\asd_task-4\asd_task_4\list.cpp
"list.h"

1583587795 source:d:\tugas kuliah\github\asd_task-4\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="725" topLine="41" />
</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="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="342" topLine="0" />
<Cursor1 position="3290" topLine="121" />
</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="list.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0">
<Cursor>
<Cursor1 position="2436" topLine="0" />
<Cursor1 position="4676" topLine="178" />
</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.h" 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="342" topLine="0" />
</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.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="270" topLine="0" />
<Cursor1 position="1219" topLine="99" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file added bin/Debug/ASD_Task_4.exe
Binary file not shown.
98 changes: 87 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,10 @@ address allocate(infotype x) {

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

P = new elmlist;
info(P) = x;
prev(P) = NULL;
next(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,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)
{
first(L) = P;
prev(P) = P;
next(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 +63,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)
{
first(L) = P;
prev(P) = P;
next(P) = P;
}
else
{
next(P) = first(L);
prev(P) = prev(first(L));
next(prev(first(L))) = P;
prev(first(L)) = P;
}
//----------------------------------------
}

Expand All @@ -60,7 +88,15 @@ address findElmByID(List L, infotype x) {

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

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

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

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

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

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

address Q = first(L);
P = prev(Q);
next(prev(P)) = Q;
prev(Q) = prev(P);
next(P) = NULL;
prev(P) = NULL;
//----------------------------------------
}

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

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

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

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

7 changes: 4 additions & 3 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +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
36 changes: 27 additions & 9 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 @@ -142,8 +140,15 @@ 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);
}
else
{
cout<<"List kosong :("<<endl;
}
//----------------------------------------
break;
case 6:
Expand All @@ -155,14 +160,26 @@ void runMenu(int menu) {
if(P != NULL){
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 != NULL)
{
cout<<"Music found"<<endl;
}
else
{
cout<<"Music not found"<<endl;
}
//----------------------------------------
cout<<"press enter";getche();
break;
Expand All @@ -182,7 +199,8 @@ void runMenu(int menu) {
case 10:
// play previous music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;
P = prev(P);
playMusic(P);

//----------------------------------------
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