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

Balqis Sayyidahtul Atikah #293

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
16 changes: 8 additions & 8 deletions ASD_Task_2.layout
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
<ActiveTarget name="Debug" />
<File name="operation.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="656" topLine="0" />
<Cursor1 position="0" topLine="1" />
</Cursor>
</File>
<File name="Main.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="837" topLine="23" />
<Cursor1 position="2649" topLine="75" />
</Cursor>
</File>
<File name="list.h" open="1" top="1" tabpos="2" 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="151" topLine="0" />
<Cursor1 position="75" topLine="19" />
</Cursor>
</File>
<File name="list.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="operation.h" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="214" topLine="117" />
<Cursor1 position="152" topLine="0" />
</Cursor>
</File>
<File name="operation.h" 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="152" topLine="0" />
<Cursor1 position="417" topLine="6" />
</Cursor>
</File>
</CodeBlocks_layout_file>
92 changes: 56 additions & 36 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@ void createList(List &L) {
* FS : set first(L) with Null
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


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

address allocate(infotype x) {
/**
* FS : return new list element with info = x and next element is Null
*/

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 +27,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 +37,10 @@ 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;



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

Expand All @@ -55,9 +50,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 Prec;
Prec=first(L);
if (first(L)== NULL){
insertFirst(L,P);
}else {
while (next(Prec) != NULL){
Prec=next(Prec);
}
insertAfter(L,Prec,P);
}
//----------------------------------------
}

Expand All @@ -70,9 +72,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 +86,12 @@ 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(P) != NULL){
first(L)=next(P);
} else {
first(L)=NULL;
}
//----------------------------------------
}

Expand All @@ -96,10 +101,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 Prec;
Prec=first(L);
if (next(Prec)== NULL){
first(L) = NULL;
} else {
while (next(next(Prec)) != NULL){
Prec=next(Prec);
}
P = next(Prec);
next(Prec) = NULL;
}
//----------------------------------------
}

Expand All @@ -109,9 +121,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 +139,10 @@ void insertAfter(List &L, address Prec, address P) {
* pointed by pointer Prec
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

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

}
Expand All @@ -136,9 +153,12 @@ 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);
if (next(P)!=NULL){
next(Prec)=next(P);
} else{
next(Prec)=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
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, Prec;
P=allocate(x);
if (first(L)==NULL){
insertFirst(L, P);
} else{
Prec=first(L);
while (next(Prec) != NULL && x > info(Prec)){
Prec=next(Prec);
}
if (x!=info(Prec)){
if(x>info(Prec)){
insertLast(L, P);
} else if(x<info(Prec)){
insertFirst(L, P);
} else{
insertAfter(L, Prec, P);
}
}
}
//----------------------------------------
}