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
18 changes: 18 additions & 0 deletions ASD_Task_2.depend
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@
"list.h"
"operation.h"

1581258151 source:c:\users\azizah cahya\documents\github\asd_task_2\operation.cpp
"list.h"
"operation.h"

1581236206 c:\users\azizah cahya\documents\github\asd_task_2\list.h
<iostream>

1581232271 c:\users\azizah cahya\documents\github\asd_task_2\operation.h
"list.h"

1581237744 source:c:\users\azizah cahya\documents\github\asd_task_2\main.cpp
<iostream>
"list.h"
"operation.h"

1581259785 source:c:\users\azizah cahya\documents\github\asd_task_2\list.cpp
"list.h"

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
Binary file added bin/Debug/ASD_Task_2.exe
Binary file not shown.
66 changes: 53 additions & 13 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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,7 +18,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;


//----------------------------------------
Expand All @@ -30,7 +32,8 @@ void deallocate(address &P) {
* FS : delete element pointed by P
*/
//-------------your code here-------------
cout<<"your code here"<<endl;
next(P) = NULL;
delete P;


//----------------------------------------
Expand All @@ -42,8 +45,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,7 +58,16 @@ 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 = first(L);
if(first(L) == NULL){
insertFirst(L, P);
}else{
while(next(Q) != NULL){
Q = next(Q);
}
next(Q) = P;
next(P) = NULL;
}


//----------------------------------------
Expand All @@ -69,8 +81,11 @@ address findElm(List L, infotype x) {
*/

address P;
P = first(L);
//-------------your code here-------------
cout<<"your code here"<<endl;
while(info(P) != x){
P = next(P);
}


//----------------------------------------
Expand All @@ -83,7 +98,13 @@ 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;
P = first(L);
if(next(first(L)) == NULL){
first(L) = NULL;
}else{
first(L) = next(P);
next(P) = NULL;
}



Expand All @@ -96,8 +117,16 @@ 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 = first(L);
if(next(Q) == NULL){
first(L) = NULL;
}else{
while(next(next(Q)) != NULL){
Q = next(Q);
}
P = next(Q);
next(Q) = NULL;
}


//----------------------------------------
Expand All @@ -109,7 +138,11 @@ 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 Q = first(L);
while(Q != NULL){
cout<<info(Q)<<", ";
Q = next(Q);
}


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

//----------------------------------------

Expand All @@ -136,7 +172,11 @@ void deleteAfter(List &L, address Prec, address &P) {
* is removed and pointed by pointer P
*/
//-------------your code here-------------
cout<<"your code here"<<endl;
if(first(L)!= NULL){
P = next(Prec);
next(Prec) = next(P);
next(P) = NULL;
}


//----------------------------------------
Expand Down
30 changes: 5 additions & 25 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,16 @@

using namespace std;


/**
* Type infotype : integer
* Type address : pointer to ElmList
*
* Type ElmList <
* info : infotype
* next : address
* >
*
* Type List : < First : address >
*
**/



typedef int infotype;
typedef struct elmlist *address;

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


//----------------------------------------
struct elmlist {
infotype info;
address next;
};

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

//----------------------------------------
struct List {
address first;
};


Expand Down
Binary file added obj/Debug/Main.o
Binary file not shown.
Binary file modified obj/Debug/list.o
Binary file not shown.
Binary file modified obj/Debug/operation.o
Binary file not shown.
22 changes: 19 additions & 3 deletions operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,24 @@ void insert_sorted(List &L, infotype x) {
*/

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


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