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

Reyhan Fadhlurohman Arrafi | 1301190356 | IF-43-05 #282

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
2 changes: 1 addition & 1 deletion Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {
//==================================================
// TEST INSERT AFTER
P = findElm(L, 6);
insertLast(L, allocate(5));
insertAfter(L, P, allocate(5));
printInfo(L);
cout<<"output should be: 8, 3, 6, 5, 4, 2,"<<endl;

Expand Down
78 changes: 44 additions & 34 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ void createList(List &L) {
* FS : set first(L) with Null
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


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

Expand All @@ -18,9 +16,9 @@ address allocate(infotype x) {

address P = NULL;
//-------------your code here-------------
cout<<"your code here"<<endl;


P = new elmlist;
info(P) = x;
next(P) = NULL;
//----------------------------------------
return P;
}
Expand All @@ -30,9 +28,7 @@ void deallocate(address &P) {
* FS : delete element pointed by P
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


delete(P);
//----------------------------------------
}

Expand All @@ -42,10 +38,8 @@ void insertFirst(List &L, address P) {
* FS : element pointed by P became the first element in List L
*/
//-------------your code here-------------
cout<<"your code here"<<endl;



next(P) = first(L);
first(L) = P;
//----------------------------------------
}

Expand All @@ -55,9 +49,12 @@ void insertLast(List &L, address P) {
* FS : element pointed by P became the last element in List L
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


address Q;
Q = first(L);
while (next(Q) != NULL) {
Q = next(Q);
}
next(Q) = P;
//----------------------------------------
}

Expand All @@ -70,8 +67,10 @@ address findElm(List L, infotype x) {

address P;
//-------------your code here-------------
cout<<"your code here"<<endl;

P = first(L);
while (P != NULL && info(P) != x){
P = next(P);
}

//----------------------------------------
return P;
Expand All @@ -83,10 +82,11 @@ void deleteFirst(List &L, address &P) {
* FS : first element in List L is removed and is pointed by P
*/
//-------------your code here-------------
cout<<"your code here"<<endl;



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

Expand All @@ -96,10 +96,17 @@ void deleteLast(List &L, address &P) {
* FS : last element in List L is removed and is pointed by P
*/
//-------------your code here-------------
cout<<"your code here"<<endl;



address Q;
Q = first(L);
if (next(Q) == NULL) {
deleteFirst(L, P);
} else {
while (next(next(Q)) != NULL) {
Q = next(Q);
}
P = next(Q);
next(Q) = NULL;
}
//----------------------------------------
}

Expand All @@ -109,9 +116,12 @@ void printInfo(List L) {
* call the view_data function from my_data.h to print the info
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


address P;
P = first(L);
while (P != NULL){
cout<<info(P);
P = next(P);
}
//----------------------------------------
cout<<endl;
}
Expand All @@ -124,8 +134,8 @@ void insertAfter(List &L, address Prec, address P) {
* pointed by pointer Prec
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

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

}
Expand All @@ -136,9 +146,9 @@ void deleteAfter(List &L, address Prec, address &P) {
* is removed and pointed by pointer P
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


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

6 changes: 3 additions & 3 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ typedef struct elmlist *address;

struct elmlist{
//------------- your code here -----------


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

struct List{
//------------- your code here -----------

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

Expand Down
14 changes: 11 additions & 3 deletions operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ void insert_sorted(List &L, infotype x) {
*/

//-------------your code here-------------
cout<<"your code here"<<endl;


address P, Q;
P = first(L);
if (P == NULL || info(P) > x) {
insertFirst(L, allocate(x));
} else if (findElm(L, x) == NULL) {
while (P != NULL && info(P) < x) {
Q = P;
P = next(P);
}
insertAfter(L, Q, allocate(x));
}
//----------------------------------------
}