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>

1583302833 source:d:\github\asd_task_4\main.cpp
"player.h"
"list.h"
<conio.h>

1582798164 d:\github\asd_task_4\player.h
"list.h"

1583304130 d:\github\asd_task_4\list.h
<string>
<windows.h>
<iostream>

1583304597 source:d:\github\asd_task_4\player.cpp
"player.h"
<ctime>

1583304130 source:d:\github\asd_task_4\list.cpp
"list.h"

18 changes: 9 additions & 9 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.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4763" topLine="177" />
<Cursor1 position="3393" topLine="156" />
</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.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="342" topLine="0" />
</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="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2436" topLine="0" />
<Cursor1 position="4965" topLine="72" />
</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.h" 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="942" topLine="6" />
</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="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="270" topLine="0" />
<Cursor1 position="2747" topLine="21" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file added bin/Debug/ASD_Task_4.exe
Binary file not shown.
141 changes: 129 additions & 12 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,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 ;
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 +63,19 @@ void insertLast(List &L, address P) {
* FS : elemen yang ditunjuk P menjadi elemen terakhir pada List L
*/
//------------- YOUR CODE HERE -------------

address Prec ;
Prec = first(L) ;
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 ;
}
//----------------------------------------
}

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

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

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

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

P = first(L) ;
do
{
P = next(P) ;
}
while ((P != first(L)) && (x.name != info(P).name)) ;
if ((P == first(L)) && (info(P).name != x.name))
{
return NULL ;
}
//----------------------------------------
return P;
}
Expand All @@ -85,7 +131,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) = NULL ;
next(P) = NULL ;
prev(P) = NULL ;
}
else
{
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 +155,19 @@ void deleteLast(List &L, address &P) {
* FS : elemen tarakhir 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 ;
first(L) = NULL ;
}
else
{
P = prev(first(L)) ;
next(prev(first(L))) = next(P) ;
prev(first(L)) = prev(P) ;
}
//----------------------------------------
}

Expand All @@ -106,9 +178,11 @@ void insertAfter(List &L, address &Prec, address P) {
* 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 @@ -117,7 +191,50 @@ 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 insertAndSort(List &L, infotype x) {
/**
* IS : List may be empty
* PR : insert a new element into an already sorted-by-ID List L
* so that the elements inside List L is still sorted by ID.
* procedure must also check if such ID is already exists (No Duplicate ID).
* If new data has duplicate ID, new data is rejected.
* FS : elements in List L sorted by ID, P is inside List L
*/

//-------------your code here-------------
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));
}
//----------------------------------------
}
9 changes: 5 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 All @@ -61,5 +61,6 @@ void deleteAfter(List &, address &, address &);
address findElmByID(List, infotype );
address findElmByName(List, infotype );

///void insertAndSort(List &L, infotype x) ;

#endif // LIST_H_INCLUDED
26 changes: 15 additions & 11 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,8 @@ void runMenu(int menu) {
case 5:
// play last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

P = prev(first(L)) ;
playMusic(P) ;
//----------------------------------------
break;
case 6:
Expand All @@ -161,8 +159,12 @@ void runMenu(int menu) {
case 7:
// search music by ID
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

cout<<"input music ID : ";
cin>>x.ID;
P = findElmByName(L, x);
if(P != NULL){
cout<<"music found"<<endl;
}
//----------------------------------------
cout<<"press enter";getche();
break;
Expand All @@ -182,8 +184,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 +206,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