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

1301190381 - Vincent Williams Jonathan - IF-43-05 #158

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
80 changes: 69 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,12 @@ address allocate(infotype x) {

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

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

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

Expand All @@ -37,7 +42,17 @@ 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,14 @@ void insertLast(List &L, address P) {
* 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;
}
//----------------------------------------
}

Expand All @@ -60,7 +82,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 @@ -74,7 +102,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 @@ -85,7 +119,12 @@ 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);
next(prev(first(L))) = next(first(L));
prev(next(first(L))) = prev(first(L));
first(L) = next(first(L));
next(P) = NULL;
prev(P) = NULL;
//----------------------------------------
}

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

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

Expand All @@ -106,7 +153,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,7 +171,11 @@ void deleteAfter(List &L, address &Prec, address &P) {
* dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

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

10 changes: 5 additions & 5 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
22 changes: 14 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +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();
Expand All @@ -142,8 +141,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,7 +160,12 @@ void runMenu(int menu) {
case 7:
// search music by ID
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;
cout<<"input ID nya lur: ";
cin>>x.ID;
P = findElmByID(L,x);
if (P != NULL){
cout<<"Musiknya ada lur\n";
}

//----------------------------------------
cout<<"press enter";getche();
Expand All @@ -182,8 +186,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 Down
42 changes: 34 additions & 8 deletions player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,24 @@ void shuffleList(List &L) {
* FS : isi (elemen) dari list teracak
*/
//------------- YOUR CODE HERE -------------

cout<<"UNDER MAIN TENIS"<<endl;

address P = first(L);
int count = 0;
do{
P = next(P);
count++;
} while (P != first(L));
while(count > 0){
P = first(L);
int i = randomInt(count);
while(i != 0){
P = next(P);
i -= 1;
}
address Q = P;
deleteAfter(L,prev(P),Q);
insertFirst(L,Q);
count -= 1;
}
//----------------------------------------
}

Expand All @@ -55,8 +70,15 @@ void playRepeat(List &L, int n) {
* dari lagu pertama hingga terakhir sebanyak n kali
*/
//------------- YOUR CODE HERE -------------

cout<<"UNDER MAIN TENIS"<<endl;
address P = first(L);
int i = 0;
while (i < n) {
do {
playMusic(P);
P = next(P);
} while (P != first(L));
i++;
}

//----------------------------------------
}
Expand All @@ -69,9 +91,13 @@ void deleteMusicByID(List &L, infotype x) {
* FS : elemen dengan ID yang dicari dideallocate
*/
//------------- YOUR CODE HERE -------------

cout<<"UNDER MAIN TENIS"<<endl;

address P;
if (first(L) != NULL) {
if (findElmByID(L, x) != NULL) {
deleteAfter(L,prev(findElmByID(L, x)), P);
deallocate(P);
}
}
//----------------------------------------

}